Skip to content

Commit

Permalink
ASoC: codecs: lpass-rx-macro: Keep static regmap_config as const
Browse files Browse the repository at this point in the history
The driver has static 'struct regmap_config', which is then customized
depending on device version.  This works fine, because there should not
be two devices in a system simultaneously and even less likely that such
two devices would have different versions, thus different regmap config.
However code is cleaner and more obvious when static data in the driver
is also const - it serves as a template.

Mark the 'struct regmap_config' as const and duplicate it in the probe()
with kmemdup to allow customizing per detected device variant.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
Link: https://patch.msgid.link/20240701-b4-qcom-audio-lpass-codec-cleanups-v3-3-6d98d4dd1ef5@linaro.org
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
krzk authored and broonie committed Jul 3, 2024
1 parent ee5e13b commit 0c02cac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sound/soc/codecs/lpass-rx-macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ static bool rx_is_readable_register(struct device *dev, unsigned int reg)
return rx_is_rw_register(dev, reg);
}

static struct regmap_config rx_regmap_config = {
static const struct regmap_config rx_regmap_config = {
.name = "rx_macro",
.reg_bits = 16,
.val_bits = 32, /* 8 but with 32 bit read/write */
Expand Down Expand Up @@ -3847,10 +3847,16 @@ static int rx_macro_probe(struct platform_device *pdev)
return -EINVAL;
}

rx_regmap_config.reg_defaults = reg_defaults;
rx_regmap_config.num_reg_defaults = def_count;
struct regmap_config *reg_config __free(kfree) = kmemdup(&rx_regmap_config,
sizeof(*reg_config),
GFP_KERNEL);
if (!reg_config)
return -ENOMEM;

reg_config->reg_defaults = reg_defaults;
reg_config->num_reg_defaults = def_count;

rx->regmap = devm_regmap_init_mmio(dev, base, &rx_regmap_config);
rx->regmap = devm_regmap_init_mmio(dev, base, reg_config);
if (IS_ERR(rx->regmap))
return PTR_ERR(rx->regmap);

Expand Down

0 comments on commit 0c02cac

Please sign in to comment.