drivers: audio: mpxxdtyy: drop device_get_binding

The bus device can be obtained at compile time, so use DEVICE_DT_GET
instead. Device configuration is now used to store the bus device
reference.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-27 12:43:37 +01:00 committed by Anas Nashif
commit 9691d6110a
3 changed files with 22 additions and 12 deletions

View file

@ -24,12 +24,13 @@ int mpxxdtyy_i2s_read(const struct device *dev, uint8_t stream, void **buffer,
size_t *size, int32_t timeout)
{
int ret;
const struct mpxxdtyy_config *config = dev->config;
struct mpxxdtyy_data *const data = dev->data;
void *pdm_block, *pcm_block;
size_t pdm_size;
TPDMFilter_InitStruct *pdm_filter = &data->pdm_filter[0];
ret = i2s_read(data->comm_master, &pdm_block, &pdm_size);
ret = i2s_read(config->comm_master, &pdm_block, &pdm_size);
if (ret != 0) {
LOG_ERR("read failed (%d)", ret);
return ret;
@ -54,6 +55,7 @@ int mpxxdtyy_i2s_read(const struct device *dev, uint8_t stream, void **buffer,
int mpxxdtyy_i2s_trigger(const struct device *dev, enum dmic_trigger cmd)
{
int ret;
const struct mpxxdtyy_config *config = dev->config;
struct mpxxdtyy_data *const data = dev->data;
enum i2s_trigger_cmd i2s_cmd;
enum dmic_state tmp_state;
@ -79,7 +81,7 @@ int mpxxdtyy_i2s_trigger(const struct device *dev, enum dmic_trigger cmd)
return -EINVAL;
}
ret = i2s_trigger(data->comm_master, I2S_DIR_RX, i2s_cmd);
ret = i2s_trigger(config->comm_master, I2S_DIR_RX, i2s_cmd);
if (ret != 0) {
LOG_ERR("trigger failed with %d error", ret);
return ret;
@ -92,6 +94,7 @@ int mpxxdtyy_i2s_trigger(const struct device *dev, enum dmic_trigger cmd)
int mpxxdtyy_i2s_configure(const struct device *dev, struct dmic_cfg *cfg)
{
int ret;
const struct mpxxdtyy_config *config = dev->config;
struct mpxxdtyy_data *const data = dev->data;
uint8_t chan_size = cfg->streams->pcm_width;
uint32_t audio_freq = cfg->streams->pcm_rate;
@ -131,7 +134,7 @@ int mpxxdtyy_i2s_configure(const struct device *dev, struct dmic_cfg *cfg)
i2s_cfg.mem_slab = &rx_pdm_i2s_mslab;
i2s_cfg.timeout = 2000;
ret = i2s_configure(data->comm_master, I2S_DIR_RX, &i2s_cfg);
ret = i2s_configure(config->comm_master, I2S_DIR_RX, &i2s_cfg);
if (ret != 0) {
LOG_ERR("I2S device configuration error");
return ret;

View file

@ -6,6 +6,8 @@
#define DT_DRV_COMPAT st_mpxxdtyy
#include <devicetree.h>
#include "mpxxdtyy.h"
#define LOG_LEVEL CONFIG_AUDIO_DMIC_LOG_LEVEL
@ -150,21 +152,23 @@ static const struct _dmic_ops mpxxdtyy_driver_api = {
static int mpxxdtyy_initialize(const struct device *dev)
{
const struct mpxxdtyy_config *config = dev->config;
struct mpxxdtyy_data *const data = dev->data;
data->comm_master = device_get_binding(DT_INST_BUS_LABEL(0));
if (data->comm_master == NULL) {
LOG_ERR("master %s not found", DT_INST_BUS_LABEL(0));
return -EINVAL;
if (!device_is_ready(config->comm_master)) {
return -ENODEV;
}
data->state = DMIC_STATE_INITIALIZED;
return 0;
}
static const struct mpxxdtyy_config mpxxdtyy_config = {
.comm_master = DEVICE_DT_GET(DT_INST_BUS(0)),
};
static struct mpxxdtyy_data mpxxdtyy_data;
DEVICE_DT_INST_DEFINE(0, mpxxdtyy_initialize, NULL, &mpxxdtyy_data, NULL,
POST_KERNEL, CONFIG_AUDIO_DMIC_INIT_PRIORITY,
&mpxxdtyy_driver_api);
DEVICE_DT_INST_DEFINE(0, mpxxdtyy_initialize, NULL, &mpxxdtyy_data,
&mpxxdtyy_config, POST_KERNEL,
CONFIG_AUDIO_DMIC_INIT_PRIORITY, &mpxxdtyy_driver_api);

View file

@ -19,8 +19,11 @@ extern "C" {
#define MPXXDTYY_MIN_PDM_FREQ 1200000 /* 1.2MHz */
#define MPXXDTYY_MAX_PDM_FREQ 3250000 /* 3.25MHz */
struct mpxxdtyy_data {
struct mpxxdtyy_config {
const struct device *comm_master;
};
struct mpxxdtyy_data {
enum dmic_state state;
TPDMFilter_InitStruct pdm_filter[2];
size_t pcm_mem_size;