Skip to content

Commit

Permalink
drivers: dai: modify dai_config_get API func
Browse files Browse the repository at this point in the history
Modify dai_config_get function to have the config struct as argument.
This was not a showstopper but a request in the API review.

In the same patch modify all Intel dai drivers using the API to preserve
bisect/compile.

Signed-off-by: Jaska Uimonen <[email protected]>
  • Loading branch information
Jaska Uimonen authored and nashif committed Feb 20, 2023
1 parent 55be5d8 commit 3b7f9c3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
11 changes: 9 additions & 2 deletions drivers/dai/intel/alh/alh.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,24 @@ static void alh_release_ownership(void)
}


static const struct dai_config *dai_alh_config_get(const struct device *dev, enum dai_dir dir)
static int dai_alh_config_get(const struct device *dev, struct dai_config *cfg,
enum dai_dir dir)
{
struct dai_config *params = (struct dai_config *)dev->config;
struct dai_intel_alh *dp = (struct dai_intel_alh *)dev->data;
struct dai_intel_alh_pdata *alh = dai_get_drvdata(dp);

if (!cfg) {
return -EINVAL;
}

params->rate = alh->params.rate;
params->channels = alh->params.channels;
params->word_size = ALH_WORD_SIZE_DEFAULT;

return params;
*cfg = *params;

return 0;
}

static int dai_alh_config_set(const struct device *dev, const struct dai_config *cfg,
Expand Down
15 changes: 11 additions & 4 deletions drivers/dai/intel/dmic/dmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,21 @@ static int dai_dmic_trigger(const struct device *dev, enum dai_dir dir,
return 0;
}

static const struct dai_config *dai_dmic_get_config(const struct device *dev, enum dai_dir dir)
static int dai_dmic_get_config(const struct device *dev, struct dai_config *cfg, enum dai_dir dir)
{
struct dai_intel_dmic *dmic = (struct dai_intel_dmic *)dev->data;

if (dir != DAI_DIR_RX)
return NULL;
if (dir != DAI_DIR_RX) {
return -EINVAL;
}

if (!cfg) {
return -EINVAL;
}

return &dmic->dai_config_params;
*cfg = dmic->dai_config_params;

return 0;
}

static int dai_dmic_set_config(const struct device *dev,
Expand Down
10 changes: 8 additions & 2 deletions drivers/dai/intel/hda/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ static int dai_hda_set_config_tplg(struct dai_intel_hda *dp, const void *spec_co
return 0;
}

static const struct dai_config *dai_hda_config_get(const struct device *dev, enum dai_dir dir)
static int dai_hda_config_get(const struct device *dev, struct dai_config *cfg, enum dai_dir dir)
{
struct dai_config *params = (struct dai_config *)dev->config;
struct dai_intel_hda *dp = (struct dai_intel_hda *)dev->data;
struct dai_intel_hda_pdata *hda = dai_get_drvdata(dp);

if (!cfg) {
return -EINVAL;
}

params->rate = hda->params.rate;
params->channels = hda->params.channels;

params->word_size = DAI_INTEL_HDA_DEFAULT_WORD_SIZE;

return params;
*cfg = *params;

return 0;
}

static int dai_hda_config_set(const struct device *dev, const struct dai_config *cfg,
Expand Down
16 changes: 12 additions & 4 deletions drivers/dai/intel/ssp/ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1825,14 +1825,20 @@ static int dai_ssp_trigger(const struct device *dev, enum dai_dir dir,
return 0;
}

static const struct dai_config *dai_ssp_config_get(const struct device *dev, enum dai_dir dir)
static int dai_ssp_config_get(const struct device *dev, struct dai_config *cfg, enum dai_dir dir)
{
struct dai_config *params = (struct dai_config *)dev->config;
struct dai_intel_ssp *dp = (struct dai_intel_ssp *)dev->data;
struct dai_intel_ssp_pdata *ssp = dai_get_drvdata(dp);

if (!ssp)
return params;
if (!cfg) {
return -EINVAL;
}

if (!ssp) {
*cfg = *params;
return 0;
}

params->rate = ssp->params.fsync_rate;

Expand All @@ -1844,7 +1850,9 @@ static const struct dai_config *dai_ssp_config_get(const struct device *dev, enu

params->word_size = ssp->params.sample_valid_bits;

return params;
*cfg = *params;

return 0;
}

static int dai_ssp_config_set(const struct device *dev, const struct dai_config *cfg,
Expand Down
15 changes: 8 additions & 7 deletions include/zephyr/drivers/dai.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ __subsystem struct dai_driver_api {
int (*remove)(const struct device *dev);
int (*config_set)(const struct device *dev, const struct dai_config *cfg,
const void *bespoke_cfg);
const struct dai_config *(*config_get)(const struct device *dev,
enum dai_dir dir);
int (*config_get)(const struct device *dev, struct dai_config *cfg,
enum dai_dir dir);

const struct dai_properties *(*get_properties)(const struct device *dev,
enum dai_dir dir,
Expand Down Expand Up @@ -328,16 +328,17 @@ static inline int dai_config_set(const struct device *dev,
* @brief Fetch configuration information of a DAI driver
*
* @param dev Pointer to the device structure for the driver instance
* @param cfg Pointer to the config structure to be filled by the instance
* @param dir Stream direction: RX or TX as defined by DAI_DIR_*
* @retval Pointer to the structure containing configuration parameters,
* or NULL if un-configured
* @retval 0 if success, negative if invalid parameters or dai un-configured
*/
static inline const struct dai_config *dai_config_get(const struct device *dev,
enum dai_dir dir)
static inline int dai_config_get(const struct device *dev,
struct dai_config *cfg,
enum dai_dir dir)
{
const struct dai_driver_api *api = (const struct dai_driver_api *)dev->api;

return api->config_get(dev, dir);
return api->config_get(dev, cfg, dir);
}

/**
Expand Down

0 comments on commit 3b7f9c3

Please sign in to comment.