cancel
Showing results for 
Search instead for 
Did you mean: 

Beep generator in CS42L51

Grodriguez
Senior

The CS42L51 used in the STM32MP15-DK2 has a beep generator that can be used to generate tones with selectable frequency and separate volume control.

Is this functionality exposed by the CS42L51 ALSA driver? Can this be used from Linux?

Thank you,

Guillermo

6 REPLIES 6
mleo
Senior II

​Hi Guillermo,

see chapter 3.3 of this article

https://wiki.st.com/stm32mpu/wiki/Soundcard_configuration

BR,

Milan

Hi Milan,

Chapter 3.3 of the linked article explains how to configure ALSA to enable the headset output and mic input. It does not say anything about the beep generator, which is what I am asking about.

Any hints?

Thanks,

Guillermo

Olivier GALLIEN
ST Employee

Hi @Grodriguez​ 

The cs42l51 driver is a driver provided by kernel community.

This driver does not expose the tone generator functionality for time being.

Additional alsa controls would have to be added in cs42l51 driver to support this features in linux.

Hope it help,

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Olivier,

Thank you for the response.

I have modified the cs42l51 driver to expose Alsa widgets for all registers related to the beep generator. These work fine -- I can modify the beep mode, duration (on/off time), frequency, and volume.

However the beep will not actually produce any sound unless the system is reproducing or recoding sound at the same time (for example via aplay or arecord). I suspect that this is due to the fact that the MCLK of the cs42l51 is generated by the STM32MP1 SAI peripheral, and thus it is only being generated when the SAI is doing playback or capture.

What should be the correct approach to handle this? Perhaps setup the SAI so that MCLK is always generated ?

Guillermo

Hi @Grodriguez​ 

Here's some hint I got from expert :

"Yes, the master clock has to be enabled to feed the audio codec.

The SAI is configured as a master clock provider on disco board.

However, the master clock will be enabled through ASoC DAPM framework

only when a playback or capture is requested.

For test purpose, the codec driver can be changed to request master clock activation on driver probe.

On probe, the driver already gets a reference to master clock. (cs42l51->mclk_handle = devm_clk_get(dev, "MCLK"))

The master clock can be enabled and configured, typically with following calls to clock framework at codec probe:

clk_prepare_enable(cs42l51->mclk_handle)

clk_set_rate_exclusive(cs42l51->mclk_handle, freq);"

Hope it help

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Olivier,

Just did the suggested quick test and indeed now the beep works.

However since the clk is set to an arbitrary rate and in exclusive mode, sound capture and playback dont work anymore. I assume this is expected and that the test you suggested was only the verify the assumption that the missing MCLK was the problem.

So, I understand that the driver needs to be modified so that the master clock is enabled via DAPM when the beep is triggered. Any suggestions or hints on how to do this? Can your expert shed some light ?

Thank you,

Guillermo