Skip to content

Commit 0c6971b

Browse files
384k: hifiberry_dacplus: Support 352k8 sample rate
Use CLK44EN for 352k8 sample rate support. Set (initial) the clk rate to CLK_48EN_RATE in the init method. Set (reset) the clk rate to CLK_48EN_RATE in the shutdown method. (Otherwise codec pcm512x_dai_startup_master method can call snd_pcm_hw_constraint_ratnums based on CLK_44EN, which will result in loss of 384k sample rate, even though we are capable of it with CLK_48EN, because 22579200/64=352800.) Signed-off-by: DigitalDreamtime <[email protected]>
1 parent 242deb4 commit 0c6971b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

sound/soc/bcm/hifiberry_dacplus.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static int snd_rpi_hifiberry_dacplus_clk_for_rate(int sample_rate)
117117
case 44100:
118118
case 88200:
119119
case 176400:
120+
case 352800:
120121
type = HIFIBERRY_DACPRO_CLK44EN;
121122
break;
122123
default:
@@ -144,7 +145,7 @@ static void snd_rpi_hifiberry_dacplus_set_sclk(struct snd_soc_codec *codec,
144145
static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
145146
{
146147
struct snd_soc_codec *codec = rtd->codec;
147-
struct pcm512x_priv *priv;
148+
struct pcm512x_priv *priv = snd_soc_codec_get_drvdata(codec);
148149

149150
if (slave)
150151
snd_rpi_hifiberry_is_dacpro = false;
@@ -163,8 +164,16 @@ static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
163164
snd_soc_update_bits(codec, PCM512x_BCLK_LRCLK_CFG, 0x31, 0x11);
164165
snd_soc_update_bits(codec, PCM512x_MASTER_MODE, 0x03, 0x03);
165166
snd_soc_update_bits(codec, PCM512x_MASTER_CLKDIV_2, 0x7f, 63);
167+
168+
/*
169+
* Default sclk to CLK_48EN_RATE, otherwise codec
170+
* pcm512x_dai_startup_master method could call
171+
* snd_pcm_hw_constraint_ratnums using CLK_44EN/64
172+
* which will mask 384k sample rate.
173+
*/
174+
if (!IS_ERR(priv->sclk))
175+
clk_set_rate(priv->sclk, CLK_48EN_RATE);
166176
} else {
167-
priv = snd_soc_codec_get_drvdata(codec);
168177
priv->sclk = ERR_PTR(-ENOENT);
169178
}
170179

@@ -264,6 +273,18 @@ static void snd_rpi_hifiberry_dacplus_shutdown(
264273
struct snd_soc_codec *codec = rtd->codec;
265274

266275
snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08, 0x00);
276+
277+
if (snd_rpi_hifiberry_is_dacpro) {
278+
struct pcm512x_priv *priv = snd_soc_codec_get_drvdata(codec);
279+
/*
280+
* Default sclk to CLK_48EN_RATE, otherwise codec
281+
* pcm512x_dai_startup_master method could call
282+
* snd_pcm_hw_constraint_ratnums using CLK_44EN/64
283+
* which will mask 384k sample rate.
284+
*/
285+
if (!IS_ERR(priv->sclk))
286+
clk_set_rate(priv->sclk, CLK_48EN_RATE);
287+
}
267288
}
268289

269290
/* machine stream operations */

0 commit comments

Comments
 (0)