Lines Matching +full:sampling +full:- +full:frequencies
4 * SPDX-License-Identifier: Apache-2.0
52 k_mem_slab_free(drv_data->mem_slab, drv_data->mem_slab_buffer); in free_buffer()
53 LOG_DBG("Freed buffer %p", drv_data->mem_slab_buffer); in free_buffer()
58 drv_data->stopping = true; in stop_pdm()
59 nrfx_pdm_stop(drv_data->pdm); in stop_pdm()
64 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in event_handler()
65 const struct dmic_nrfx_pdm_drv_cfg *drv_cfg = dev->config; in event_handler()
69 if (evt->buffer_requested) { in event_handler()
73 ret = k_mem_slab_alloc(drv_data->mem_slab, &drv_data->mem_slab_buffer, K_NO_WAIT); in event_handler()
78 ret = dmm_buffer_in_prepare(drv_cfg->mem_reg, drv_data->mem_slab_buffer, in event_handler()
79 drv_data->block_size, &buffer); in event_handler()
85 err = nrfx_pdm_buffer_set(drv_data->pdm, buffer, drv_data->block_size / 2); in event_handler()
93 if (drv_data->stopping) { in event_handler()
94 if (evt->buffer_released) { in event_handler()
95 ret = dmm_buffer_in_release(drv_cfg->mem_reg, drv_data->mem_slab_buffer, in event_handler()
96 drv_data->block_size, evt->buffer_released); in event_handler()
105 if (drv_data->active) { in event_handler()
106 drv_data->active = false; in event_handler()
107 if (drv_data->request_clock) { in event_handler()
108 (void)onoff_release(drv_data->clk_mgr); in event_handler()
111 } else if (evt->buffer_released) { in event_handler()
112 ret = dmm_buffer_in_release(drv_cfg->mem_reg, drv_data->mem_slab_buffer, in event_handler()
113 drv_data->block_size, evt->buffer_released); in event_handler()
119 ret = k_msgq_put(&drv_data->rx_queue, in event_handler()
120 &drv_data->mem_slab_buffer, in event_handler()
127 LOG_DBG("Queued buffer %p", evt->buffer_released); in event_handler()
137 return freq >= pdm_cfg->io.min_pdm_clk_freq && freq <= pdm_cfg->io.max_pdm_clk_freq; in is_in_freq_range()
148 uint32_t diff = act_rate >= req_rate ? (act_rate - req_rate) in is_better()
149 : (req_rate - act_rate); in is_better()
171 uint32_t req_rate = pdm_cfg->streams[0].pcm_rate; in check_pdm_frequencies()
182 config->prescaler = prescaler; in check_pdm_frequencies()
200 config->prescaler = prescaler; in check_pdm_frequencies()
207 (NRF_PDM_HAS_MCLKCONFIG && drv_cfg->clk_src == ACLK) in check_pdm_frequencies()
211 * with the "hfclkaudio-frequency" property defined, in check_pdm_frequencies()
237 config->clock_freq = clk_factor * 4096; in check_pdm_frequencies()
241 } else { /* -> !IS_ENABLED(CONFIG_SOC_SERIES_NRF53X)) */ in check_pdm_frequencies()
263 if (freq_val < pdm_cfg->io.min_pdm_clk_freq) { in check_pdm_frequencies()
266 if (freq_val > pdm_cfg->io.max_pdm_clk_freq) { in check_pdm_frequencies()
272 config->clock_freq = freqs[i].freq_enum; in check_pdm_frequencies()
282 /* Since frequencies are in ascending order, stop in check_pdm_frequencies()
339 config->ratio = ratios[r].ratio_enum; in find_suitable_clock()
368 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in dmic_nrfx_pdm_configure()
369 const struct dmic_nrfx_pdm_drv_cfg *drv_cfg = dev->config; in dmic_nrfx_pdm_configure()
370 struct pdm_chan_cfg *channel = &config->channel; in dmic_nrfx_pdm_configure()
371 struct pcm_stream_cfg *stream = &config->streams[0]; in dmic_nrfx_pdm_configure()
376 if (drv_data->active) { in dmic_nrfx_pdm_configure()
378 return -EBUSY; in dmic_nrfx_pdm_configure()
383 * 16-bit samples for two channels (Left+Right samples) or one channel in dmic_nrfx_pdm_configure()
385 * by changing the PDM_CLK edge on which the sampling is done in dmic_nrfx_pdm_configure()
390 if (channel->req_num_chan == 1) { in dmic_nrfx_pdm_configure()
394 channel->act_num_chan = 1; in dmic_nrfx_pdm_configure()
401 channel->act_num_chan = 2; in dmic_nrfx_pdm_configure()
404 channel->act_num_streams = 1; in dmic_nrfx_pdm_configure()
405 channel->act_chan_map_hi = 0; in dmic_nrfx_pdm_configure()
406 channel->act_chan_map_lo = def_map; in dmic_nrfx_pdm_configure()
408 if (channel->req_num_streams != 1 || in dmic_nrfx_pdm_configure()
409 channel->req_num_chan > 2 || in dmic_nrfx_pdm_configure()
410 channel->req_num_chan < 1 || in dmic_nrfx_pdm_configure()
411 (channel->req_chan_map_lo != def_map && in dmic_nrfx_pdm_configure()
412 channel->req_chan_map_lo != alt_map) || in dmic_nrfx_pdm_configure()
413 channel->req_chan_map_hi != channel->act_chan_map_hi) { in dmic_nrfx_pdm_configure()
415 return -EINVAL; in dmic_nrfx_pdm_configure()
419 if (stream->pcm_rate == 0 || stream->pcm_width == 0) { in dmic_nrfx_pdm_configure()
420 if (drv_data->configured) { in dmic_nrfx_pdm_configure()
421 nrfx_pdm_uninit(drv_data->pdm); in dmic_nrfx_pdm_configure()
422 drv_data->configured = false; in dmic_nrfx_pdm_configure()
428 if (stream->pcm_width != 16) { in dmic_nrfx_pdm_configure()
429 LOG_ERR("Only 16-bit samples are supported"); in dmic_nrfx_pdm_configure()
430 return -EINVAL; in dmic_nrfx_pdm_configure()
433 nrfx_cfg = drv_cfg->nrfx_def_cfg; in dmic_nrfx_pdm_configure()
434 nrfx_cfg.mode = channel->req_num_chan == 1 in dmic_nrfx_pdm_configure()
437 nrfx_cfg.edge = channel->req_chan_map_lo == def_map in dmic_nrfx_pdm_configure()
441 nrfx_cfg.mclksrc = drv_cfg->clk_src == ACLK in dmic_nrfx_pdm_configure()
447 return -EINVAL; in dmic_nrfx_pdm_configure()
450 if (drv_data->configured) { in dmic_nrfx_pdm_configure()
451 nrfx_pdm_uninit(drv_data->pdm); in dmic_nrfx_pdm_configure()
452 drv_data->configured = false; in dmic_nrfx_pdm_configure()
455 err = nrfx_pdm_init(drv_data->pdm, &nrfx_cfg, drv_cfg->event_handler); in dmic_nrfx_pdm_configure()
458 return -EIO; in dmic_nrfx_pdm_configure()
461 drv_data->block_size = stream->block_size; in dmic_nrfx_pdm_configure()
462 drv_data->mem_slab = stream->mem_slab; in dmic_nrfx_pdm_configure()
469 drv_data->request_clock = (drv_cfg->clk_src != PCLK32M); in dmic_nrfx_pdm_configure()
470 drv_data->configured = true; in dmic_nrfx_pdm_configure()
479 err = nrfx_pdm_start(drv_data->pdm); in start_transfer()
485 ret = -EIO; in start_transfer()
487 if (drv_data->request_clock) { in start_transfer()
488 (void)onoff_release(drv_data->clk_mgr); in start_transfer()
491 drv_data->active = false; in start_transfer()
507 if (!drv_data->active) { in clock_started_callback()
508 (void)onoff_release(drv_data->clk_mgr); in clock_started_callback()
516 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in trigger_start()
519 drv_data->active = true; in trigger_start()
524 if (drv_data->request_clock) { in trigger_start()
525 sys_notify_init_callback(&drv_data->clk_cli.notify, in trigger_start()
527 ret = onoff_request(drv_data->clk_mgr, &drv_data->clk_cli); in trigger_start()
529 drv_data->active = false; in trigger_start()
532 return -EIO; in trigger_start()
547 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in dmic_nrfx_pdm_trigger()
552 if (drv_data->active) { in dmic_nrfx_pdm_trigger()
553 drv_data->stopping = true; in dmic_nrfx_pdm_trigger()
554 nrfx_pdm_stop(drv_data->pdm); in dmic_nrfx_pdm_trigger()
560 if (!drv_data->configured) { in dmic_nrfx_pdm_trigger()
562 return -EIO; in dmic_nrfx_pdm_trigger()
563 } else if (!drv_data->active) { in dmic_nrfx_pdm_trigger()
564 drv_data->stopping = false; in dmic_nrfx_pdm_trigger()
571 return -EINVAL; in dmic_nrfx_pdm_trigger()
581 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in dmic_nrfx_pdm_read()
586 if (!drv_data->configured) { in dmic_nrfx_pdm_read()
588 return -EIO; in dmic_nrfx_pdm_read()
591 ret = k_msgq_get(&drv_data->rx_queue, buffer, SYS_TIMEOUT_MS(timeout)); in dmic_nrfx_pdm_read()
597 *size = drv_data->block_size; in dmic_nrfx_pdm_read()
606 struct dmic_nrfx_pdm_drv_data *drv_data = dev->data; in init_clock_manager()
610 const struct dmic_nrfx_pdm_drv_cfg *drv_cfg = dev->config; in init_clock_manager()
612 if (drv_cfg->clk_src == ACLK) { in init_clock_manager()
620 drv_data->clk_mgr = z_nrf_clock_control_get_onoff(subsys); in init_clock_manager()
621 __ASSERT_NO_MSG(drv_data->clk_mgr != NULL); in init_clock_manager()
642 const struct dmic_nrfx_pdm_drv_cfg *drv_cfg = dev->config; \
643 int err = pinctrl_apply_state(drv_cfg->pcfg, \
675 "Clock source ACLK requires the hfclkaudio-frequency " \
676 "property to be defined in the nordic,nrf-clock node."); \