Skip to content

Commit 36cdf4a

Browse files
nordic-seglnordicjm
authored andcommitted
Revert "[nrf fromlist] drivers: audio: dmic_nrfx: add support for audio clocks on nRF54"
This reverts commit e48bca4. Signed-off-by: Sebastian Głąb <[email protected]>
1 parent 926f142 commit 36cdf4a

File tree

1 file changed

+36
-76
lines changed

1 file changed

+36
-76
lines changed

drivers/audio/dmic_nrfx_pdm.c

Lines changed: 36 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,14 @@ LOG_MODULE_REGISTER(dmic_nrfx_pdm, CONFIG_AUDIO_DMIC_LOG_LEVEL);
1818
#if CONFIG_SOC_SERIES_NRF54HX
1919
#define DMIC_NRFX_CLOCK_FREQ MHZ(16)
2020
#define DMIC_NRFX_CLOCK_FACTOR 8192
21-
#define DMIC_NRFX_AUDIO_CLOCK_FREQ DT_PROP_OR(DT_NODELABEL(audiopll), frequency, 0)
2221
#else
2322
#define DMIC_NRFX_CLOCK_FREQ MHZ(32)
2423
#define DMIC_NRFX_CLOCK_FACTOR 4096
25-
#define DMIC_NRFX_AUDIO_CLOCK_FREQ \
26-
COND_CODE_1(CONFIG_SOC_NRF54L20, \
27-
(DT_PROP_OR(DT_NODELABEL(aclk), clock_frequency, 0)), \
28-
(DT_PROP_OR(DT_NODELABEL(clock), hfclkaudio_frequency, 0)))
2924
#endif
3025

3126
struct dmic_nrfx_pdm_drv_data {
3227
const nrfx_pdm_t *pdm;
33-
#if CONFIG_CLOCK_CONTROL_NRF
3428
struct onoff_manager *clk_mgr;
35-
#elif CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL
36-
const struct device *audiopll_dev;
37-
#endif
3829
struct onoff_client clk_cli;
3930
struct k_mem_slab *mem_slab;
4031
uint32_t block_size;
@@ -70,35 +61,6 @@ static void stop_pdm(struct dmic_nrfx_pdm_drv_data *drv_data)
7061
nrfx_pdm_stop(drv_data->pdm);
7162
}
7263

73-
static int request_clock(struct dmic_nrfx_pdm_drv_data *drv_data)
74-
{
75-
if (!drv_data->request_clock) {
76-
return 0;
77-
}
78-
#if CONFIG_CLOCK_CONTROL_NRF
79-
return onoff_request(drv_data->clk_mgr, &drv_data->clk_cli);
80-
#elif CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL
81-
return nrf_clock_control_request(drv_data->audiopll_dev, NULL, &drv_data->clk_cli);
82-
#else
83-
return 0;
84-
#endif
85-
}
86-
87-
static int release_clock(struct dmic_nrfx_pdm_drv_data *drv_data)
88-
{
89-
if (!drv_data->request_clock) {
90-
return 0;
91-
}
92-
93-
#if CONFIG_CLOCK_CONTROL_NRF
94-
return onoff_release(drv_data->clk_mgr);
95-
#elif CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL
96-
return nrf_clock_control_release(drv_data->audiopll_dev, NULL);
97-
#else
98-
return 0;
99-
#endif
100-
}
101-
10264
static void event_handler(const struct device *dev, const nrfx_pdm_evt_t *evt)
10365
{
10466
struct dmic_nrfx_pdm_drv_data *drv_data = dev->data;
@@ -157,10 +119,8 @@ static void event_handler(const struct device *dev, const nrfx_pdm_evt_t *evt)
157119

158120
if (drv_data->active) {
159121
drv_data->active = false;
160-
ret = release_clock(drv_data);
161-
if (ret < 0) {
162-
LOG_ERR("Failed to release clock: %d", ret);
163-
return;
122+
if (drv_data->request_clock) {
123+
(void)onoff_release(drv_data->clk_mgr);
164124
}
165125
}
166126
} else if (evt->buffer_released) {
@@ -231,11 +191,9 @@ static bool check_pdm_frequencies(const struct dmic_nrfx_pdm_drv_cfg *drv_cfg,
231191
{
232192
uint32_t req_rate = pdm_cfg->streams[0].pcm_rate;
233193
bool better_found = false;
234-
const uint32_t src_freq =
235-
(NRF_PDM_HAS_SELECTABLE_CLOCK && drv_cfg->clk_src == ACLK)
236-
? DMIC_NRFX_AUDIO_CLOCK_FREQ
237-
: DMIC_NRFX_CLOCK_FREQ;
194+
238195
#if NRF_PDM_HAS_PRESCALER
196+
uint32_t src_freq = 32 * 1000 * 1000UL;
239197
uint32_t req_freq = req_rate * ratio;
240198
uint32_t prescaler = src_freq / req_freq;
241199
uint32_t act_freq = src_freq / prescaler;
@@ -266,6 +224,24 @@ static bool check_pdm_frequencies(const struct dmic_nrfx_pdm_drv_cfg *drv_cfg,
266224
}
267225
#else
268226
if (IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || IS_ENABLED(CONFIG_SOC_SERIES_NRF54HX)) {
227+
const uint32_t src_freq =
228+
(NRF_PDM_HAS_MCLKCONFIG && drv_cfg->clk_src == ACLK)
229+
/* The DMIC_NRFX_PDM_DEVICE() macro contains build
230+
* assertions that make sure that the ACLK clock
231+
* source is only used when it is available and only
232+
* with the "hfclkaudio-frequency" property defined,
233+
* but the default value of 0 here needs to be used
234+
* to prevent compilation errors when the property is
235+
* not defined (this expression will be eventually
236+
* optimized away then).
237+
*/
238+
/* TODO : PS does not provide correct formula for nRF54H20 PDM_CLK.
239+
* Assume that master clock source frequency is 8 MHz. Remove once
240+
* correct formula is found.
241+
*/
242+
? DT_PROP_OR(DT_NODELABEL(clock), hfclkaudio_frequency,
243+
0)
244+
: DMIC_NRFX_CLOCK_FREQ;
269245
uint32_t req_freq = req_rate * ratio;
270246
/* As specified in the nRF5340 PS:
271247
*
@@ -485,7 +461,7 @@ static int dmic_nrfx_pdm_configure(const struct device *dev,
485461
nrfx_cfg.edge = NRF_PDM_EDGE_LEFTRISING;
486462
channel->act_chan_map_lo = alt_map;
487463
}
488-
#if NRF_PDM_HAS_SELECTABLE_CLOCK
464+
#if NRF_PDM_HAS_MCLKCONFIG
489465
nrfx_cfg.mclksrc = drv_cfg->clk_src == ACLK
490466
? NRF_PDM_MCLKSRC_ACLK
491467
: NRF_PDM_MCLKSRC_PCLK32M;
@@ -532,10 +508,8 @@ static int start_transfer(struct dmic_nrfx_pdm_drv_data *drv_data)
532508
LOG_ERR("Failed to start PDM: 0x%08x", err);
533509
ret = -EIO;
534510

535-
ret = release_clock(drv_data);
536-
if (ret < 0) {
537-
LOG_ERR("Failed to release clock: %d", ret);
538-
return ret;
511+
if (drv_data->request_clock) {
512+
(void)onoff_release(drv_data->clk_mgr);
539513
}
540514

541515
drv_data->active = false;
@@ -555,12 +529,7 @@ static void clock_started_callback(struct onoff_manager *mgr,
555529
* the actual transfer in such case.
556530
*/
557531
if (!drv_data->active) {
558-
int ret = release_clock(drv_data);
559-
560-
if (ret < 0) {
561-
LOG_ERR("Failed to release clock: %d", ret);
562-
return;
563-
}
532+
(void)onoff_release(drv_data->clk_mgr);
564533
} else {
565534
(void)start_transfer(drv_data);
566535
}
@@ -579,7 +548,7 @@ static int trigger_start(const struct device *dev)
579548
if (drv_data->request_clock) {
580549
sys_notify_init_callback(&drv_data->clk_cli.notify,
581550
clock_started_callback);
582-
ret = request_clock(drv_data);
551+
ret = onoff_request(drv_data->clk_mgr, &drv_data->clk_cli);
583552
if (ret < 0) {
584553
drv_data->active = false;
585554

@@ -655,11 +624,12 @@ static int dmic_nrfx_pdm_read(const struct device *dev,
655624
return ret;
656625
}
657626

627+
#if CONFIG_CLOCK_CONTROL_NRF
658628
static void init_clock_manager(const struct device *dev)
659629
{
660-
#if CONFIG_CLOCK_CONTROL_NRF
661-
clock_control_subsys_t subsys;
662630
struct dmic_nrfx_pdm_drv_data *drv_data = dev->data;
631+
clock_control_subsys_t subsys;
632+
663633
#if NRF_CLOCK_HAS_HFCLKAUDIO
664634
const struct dmic_nrfx_pdm_drv_cfg *drv_cfg = dev->config;
665635

@@ -673,12 +643,8 @@ static void init_clock_manager(const struct device *dev)
673643

674644
drv_data->clk_mgr = z_nrf_clock_control_get_onoff(subsys);
675645
__ASSERT_NO_MSG(drv_data->clk_mgr != NULL);
676-
#elif CONFIG_CLOCK_CONTROL_NRF2_AUDIOPLL
677-
struct dmic_nrfx_pdm_drv_data *drv_data = dev->data;
678-
679-
drv_data->audiopll_dev = DEVICE_DT_GET(DT_NODELABEL(audiopll));
680-
#endif
681646
}
647+
#endif
682648

683649
static const struct _dmic_ops dmic_ops = {
684650
.configure = dmic_nrfx_pdm_configure,
@@ -711,7 +677,8 @@ static const struct _dmic_ops dmic_ops = {
711677
k_msgq_init(&dmic_nrfx_pdm_data##idx.mem_slab_queue, \
712678
(char *)mem_slab_msgs##idx, sizeof(void *), \
713679
ARRAY_SIZE(mem_slab_msgs##idx)); \
714-
init_clock_manager(dev); \
680+
IF_ENABLED(CONFIG_CLOCK_CONTROL_NRF, \
681+
(init_clock_manager(dev);)) \
715682
return 0; \
716683
} \
717684
static void event_handler##idx(const nrfx_pdm_evt_t *evt) \
@@ -728,20 +695,13 @@ static const struct _dmic_ops dmic_ops = {
728695
.clk_src = PDM_CLK_SRC(idx), \
729696
.mem_reg = DMM_DEV_TO_REG(PDM(idx)), \
730697
}; \
731-
BUILD_ASSERT(PDM_CLK_SRC(idx) != ACLK || \
732-
NRF_PDM_HAS_SELECTABLE_CLOCK, \
698+
BUILD_ASSERT(PDM_CLK_SRC(idx) != ACLK || NRF_PDM_HAS_MCLKCONFIG, \
733699
"Clock source ACLK is not available."); \
734700
BUILD_ASSERT(PDM_CLK_SRC(idx) != ACLK || \
735701
DT_NODE_HAS_PROP(DT_NODELABEL(clock), \
736-
hfclkaudio_frequency) || \
737-
DT_NODE_HAS_PROP(DT_NODELABEL(aclk), \
738-
clock_frequency) || \
739-
DT_NODE_HAS_PROP(DT_NODELABEL(audiopll), \
740-
frequency), \
702+
hfclkaudio_frequency), \
741703
"Clock source ACLK requires the hfclkaudio-frequency " \
742-
"property to be defined in the nordic,nrf-clock node " \
743-
"or clock-frequency property to be defined in aclk node" \
744-
"or frequency property to be defined in audiopll node"); \
704+
"property to be defined in the nordic,nrf-clock node."); \
745705
DEVICE_DT_DEFINE(PDM(idx), pdm_nrfx_init##idx, NULL, \
746706
&dmic_nrfx_pdm_data##idx, &dmic_nrfx_pdm_cfg##idx, \
747707
POST_KERNEL, CONFIG_AUDIO_DMIC_INIT_PRIORITY, \

0 commit comments

Comments
 (0)