ASoC: soc-component: add snd_soc_component_regmap_val_bytes()
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> says: component has component->val_bytes which is set via snd_soc_component_setup_regmap(). But it can be calculated via component->regmap. No need to keep it as component->val_bytes. This patchset adds new snd_soc_component_regmap_val_bytes(), and remove component->val_bytes / snd_soc_component_setup_regmap(). Link: https://patch.msgid.link/87a4wdzyxf.wl-kuninori.morimoto.gx@renesas.com
This commit is contained in:
7 files changed
+46
-27
No files matched your search
@@ -224,7 +224,6 @@ struct snd_soc_component {
|
||||
int num_dai;
|
||||
|
||||
struct regmap *regmap;
|
||||
int val_bytes;
|
||||
|
||||
struct mutex io_mutex;
|
||||
|
||||
@@ -327,7 +326,7 @@ int snd_soc_component_stream_event(struct snd_soc_component *component,
|
||||
int snd_soc_component_set_bias_level(struct snd_soc_component *component,
|
||||
enum snd_soc_bias_level level);
|
||||
|
||||
void snd_soc_component_setup_regmap(struct snd_soc_component *component);
|
||||
int snd_soc_component_regmap_val_bytes(struct snd_soc_component *component);
|
||||
#ifdef CONFIG_REGMAP
|
||||
void snd_soc_component_init_regmap(struct snd_soc_component *component,
|
||||
struct regmap *regmap);
|
||||
|
||||
@@ -342,14 +342,22 @@ int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
|
||||
return -ENOTSUPP;
|
||||
}
|
||||
|
||||
void snd_soc_component_setup_regmap(struct snd_soc_component *component)
|
||||
int snd_soc_component_regmap_val_bytes(struct snd_soc_component *component)
|
||||
{
|
||||
int val_bytes = regmap_get_val_bytes(component->regmap);
|
||||
int val_bytes;
|
||||
|
||||
/* Errors are legitimate for non-integer byte multiples */
|
||||
if (val_bytes > 0)
|
||||
component->val_bytes = val_bytes;
|
||||
|
||||
if (!component->regmap)
|
||||
return 0;
|
||||
|
||||
val_bytes = regmap_get_val_bytes(component->regmap);
|
||||
if (val_bytes < 0)
|
||||
return 0;
|
||||
|
||||
return val_bytes;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_component_regmap_val_bytes);
|
||||
|
||||
#ifdef CONFIG_REGMAP
|
||||
|
||||
@@ -368,7 +376,6 @@ void snd_soc_component_init_regmap(struct snd_soc_component *component,
|
||||
struct regmap *regmap)
|
||||
{
|
||||
component->regmap = regmap;
|
||||
snd_soc_component_setup_regmap(component);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
|
||||
|
||||
|
||||
@@ -2906,8 +2906,6 @@ int snd_soc_add_component(struct snd_soc_component *component,
|
||||
if (!component->regmap)
|
||||
component->regmap = dev_get_regmap(component->dev,
|
||||
NULL);
|
||||
if (component->regmap)
|
||||
snd_soc_component_setup_regmap(component);
|
||||
}
|
||||
|
||||
/* see for_each_component */
|
||||
|
||||
+12
-7
@@ -472,9 +472,10 @@ int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
|
||||
{
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_bytes *params = (void *)kcontrol->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(component);
|
||||
|
||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
|
||||
uinfo->count = params->num_regs * component->val_bytes;
|
||||
uinfo->count = params->num_regs * val_bytes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -485,18 +486,19 @@ int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
|
||||
{
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_bytes *params = (void *)kcontrol->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(component);
|
||||
int ret;
|
||||
|
||||
if (component->regmap)
|
||||
ret = regmap_raw_read(component->regmap, params->base,
|
||||
ucontrol->value.bytes.data,
|
||||
params->num_regs * component->val_bytes);
|
||||
params->num_regs * val_bytes);
|
||||
else
|
||||
ret = -EINVAL;
|
||||
|
||||
/* Hide any masked bytes to ensure consistent data reporting */
|
||||
if (ret == 0 && params->mask) {
|
||||
switch (component->val_bytes) {
|
||||
switch (val_bytes) {
|
||||
case 1:
|
||||
ucontrol->value.bytes.data[0] &= ~params->mask;
|
||||
break;
|
||||
@@ -522,13 +524,14 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
|
||||
{
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_bytes *params = (void *)kcontrol->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(component);
|
||||
unsigned int val, mask;
|
||||
int ret, len;
|
||||
|
||||
if (!component->regmap || !params->num_regs)
|
||||
return -EINVAL;
|
||||
|
||||
len = params->num_regs * component->val_bytes;
|
||||
len = params->num_regs * val_bytes;
|
||||
|
||||
void *data __free(kfree) = kmemdup(ucontrol->value.bytes.data, len,
|
||||
GFP_KERNEL | GFP_DMA);
|
||||
@@ -547,7 +550,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
|
||||
|
||||
val &= params->mask;
|
||||
|
||||
switch (component->val_bytes) {
|
||||
switch (val_bytes) {
|
||||
case 1:
|
||||
((u8 *)data)[0] &= ~params->mask;
|
||||
((u8 *)data)[0] |= val;
|
||||
@@ -670,9 +673,10 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_mreg_control *mc =
|
||||
(struct soc_mreg_control *)kcontrol->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(component);
|
||||
unsigned int regbase = mc->regbase;
|
||||
unsigned int regcount = mc->regcount;
|
||||
unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
|
||||
unsigned int regwshift = val_bytes * BITS_PER_BYTE;
|
||||
unsigned int regwmask = GENMASK(regwshift - 1, 0);
|
||||
unsigned long mask = GENMASK(mc->nbits - 1, 0);
|
||||
long val = 0;
|
||||
@@ -714,9 +718,10 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
|
||||
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
|
||||
struct soc_mreg_control *mc =
|
||||
(struct soc_mreg_control *)kcontrol->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(component);
|
||||
unsigned int regbase = mc->regbase;
|
||||
unsigned int regcount = mc->regcount;
|
||||
unsigned int regwshift = component->val_bytes * BITS_PER_BYTE;
|
||||
unsigned int regwshift = val_bytes * BITS_PER_BYTE;
|
||||
unsigned int regwmask = GENMASK(regwshift - 1, 0);
|
||||
unsigned long mask = GENMASK(mc->nbits - 1, 0);
|
||||
long val = ucontrol->value.integer.value[0];
|
||||
|
||||
@@ -20,6 +20,7 @@ static int tegra_ahub_get_value_enum(struct snd_kcontrol *kctl,
|
||||
struct snd_soc_component *cmpnt = snd_soc_dapm_kcontrol_to_component(kctl);
|
||||
struct tegra_ahub *ahub = snd_soc_component_get_drvdata(cmpnt);
|
||||
struct soc_enum *e = (struct soc_enum *)kctl->private_value;
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
unsigned int reg, i, bit_pos = 0;
|
||||
|
||||
/*
|
||||
@@ -35,7 +36,7 @@ static int tegra_ahub_get_value_enum(struct snd_kcontrol *kctl,
|
||||
|
||||
if (reg_val) {
|
||||
bit_pos = ffs(reg_val) +
|
||||
(8 * cmpnt->val_bytes * i);
|
||||
(8 * val_bytes * i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +60,7 @@ static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
|
||||
struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_to_dapm(kctl);
|
||||
struct soc_enum *e = (struct soc_enum *)kctl->private_value;
|
||||
struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { };
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
unsigned int *item = uctl->value.enumerated.item;
|
||||
unsigned int value = e->values[item[0]];
|
||||
unsigned int i, bit_pos, reg_idx = 0, reg_val = 0;
|
||||
@@ -69,8 +71,8 @@ static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
|
||||
|
||||
if (value) {
|
||||
/* Get the register index and value to set */
|
||||
reg_idx = (value - 1) / (8 * cmpnt->val_bytes);
|
||||
bit_pos = (value - 1) % (8 * cmpnt->val_bytes);
|
||||
reg_idx = (value - 1) / (8 * val_bytes);
|
||||
bit_pos = (value - 1) % (8 * val_bytes);
|
||||
reg_val = BIT(bit_pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,13 +307,14 @@ static int tegra210_mbdrc_band_params_get(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
u32 regs = params->soc.base;
|
||||
u32 mask = params->soc.mask;
|
||||
u32 shift = params->shift;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < params->soc.num_regs; i++, regs += cmpnt->val_bytes) {
|
||||
for (i = 0; i < params->soc.num_regs; i++, regs += val_bytes) {
|
||||
regmap_read(ope->mbdrc_regmap, regs, &data[i]);
|
||||
|
||||
data[i] = ((data[i] & mask) >> shift);
|
||||
@@ -328,6 +329,7 @@ static int tegra210_mbdrc_band_params_put(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
u32 regs = params->soc.base;
|
||||
u32 mask = params->soc.mask;
|
||||
@@ -335,7 +337,7 @@ static int tegra210_mbdrc_band_params_put(struct snd_kcontrol *kcontrol,
|
||||
bool change = false;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < params->soc.num_regs; i++, regs += cmpnt->val_bytes) {
|
||||
for (i = 0; i < params->soc.num_regs; i++, regs += val_bytes) {
|
||||
bool update = false;
|
||||
|
||||
regmap_update_bits_check(ope->mbdrc_regmap, regs, mask,
|
||||
@@ -353,13 +355,14 @@ static int tegra210_mbdrc_threshold_get(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
u32 regs = params->soc.base;
|
||||
u32 num_regs = params->soc.num_regs;
|
||||
u32 val;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < num_regs; i += 4, regs += cmpnt->val_bytes) {
|
||||
for (i = 0; i < num_regs; i += 4, regs += val_bytes) {
|
||||
regmap_read(ope->mbdrc_regmap, regs, &val);
|
||||
|
||||
data[i] = (val & TEGRA210_MBDRC_THRESH_1ST_MASK) >>
|
||||
@@ -381,13 +384,14 @@ static int tegra210_mbdrc_threshold_put(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
u32 regs = params->soc.base;
|
||||
u32 num_regs = params->soc.num_regs;
|
||||
bool change = false;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < num_regs; i += 4, regs += cmpnt->val_bytes) {
|
||||
for (i = 0; i < num_regs; i += 4, regs += val_bytes) {
|
||||
bool update = false;
|
||||
|
||||
data[i] = (((data[i] >> TEGRA210_MBDRC_THRESH_1ST_SHIFT) &
|
||||
@@ -413,9 +417,10 @@ static int tegra210_mbdrc_biquad_coeffs_get(struct snd_kcontrol *kcontrol,
|
||||
{
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
|
||||
memset(data, 0, params->soc.num_regs * cmpnt->val_bytes);
|
||||
memset(data, 0, params->soc.num_regs * val_bytes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -426,8 +431,9 @@ static int tegra210_mbdrc_biquad_coeffs_put(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 reg_ctrl = params->soc.base;
|
||||
u32 reg_data = reg_ctrl + cmpnt->val_bytes;
|
||||
u32 reg_data = reg_ctrl + val_bytes;
|
||||
u32 *data = (u32 *)ucontrol->value.bytes.data;
|
||||
|
||||
tegra210_mbdrc_write_ram(ope->mbdrc_regmap, reg_ctrl, reg_data,
|
||||
|
||||
@@ -148,8 +148,9 @@ static int tegra210_peq_ram_get(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 i, reg_ctrl = params->soc.base;
|
||||
u32 reg_data = reg_ctrl + cmpnt->val_bytes;
|
||||
u32 reg_data = reg_ctrl + val_bytes;
|
||||
s32 *data = (s32 *)biquad_coeff_buffer;
|
||||
|
||||
pm_runtime_get_sync(cmpnt->dev);
|
||||
@@ -171,8 +172,9 @@ static int tegra210_peq_ram_put(struct snd_kcontrol *kcontrol,
|
||||
struct tegra_soc_bytes *params = (void *)kcontrol->private_value;
|
||||
struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
|
||||
struct tegra210_ope *ope = snd_soc_component_get_drvdata(cmpnt);
|
||||
int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
|
||||
u32 i, reg_ctrl = params->soc.base;
|
||||
u32 reg_data = reg_ctrl + cmpnt->val_bytes;
|
||||
u32 reg_data = reg_ctrl + val_bytes;
|
||||
s32 *data = (s32 *)biquad_coeff_buffer;
|
||||
|
||||
for (i = 0; i < params->soc.num_regs; i++)
|
||||
|
||||
Reference in new issue
Block a user