[PATCH 16/26] clk: amlogic: add probe helper for mmio based controllers

Jerome Brunet jbrunet at baylibre.com
Thu Jul 3 01:35:51 PDT 2025


On Thu 03 Jul 2025 at 11:29, Chuan Liu <chuan.liu at amlogic.com> wrote:

>>
>> +static const struct regmap_config base_clkc_regmap_cfg = {
>> +       .reg_bits       = 32,
>> +       .val_bits       = 32,
>> +       .reg_stride     = 4,
>> +};
>> +
>
>
> Since 'base_clkc_regmap_cfg' is only referenced within
> 'meson_clkc_mmio_probe()',
> we should move it as a local variable inside the function. This would be
> more
> logical and may optimize code size (During compiler optimization, only
> critical
> data needs to be preserved rather than the entire structure?)
>
>
>> +int meson_clkc_mmio_probe(struct platform_device *pdev)
>> +{
>> +       const struct meson_clkc_data *data;
>> +       struct device *dev = &pdev->dev;
>> +       struct regmap_config regmap_cfg;

Actually a partial init would do the job nicely. I'll refine this on v2

>> +       struct resource *res;
>> +       void __iomem *base;
>> +       struct regmap *map;
>> +
>> +       data = of_device_get_match_data(dev);
>> +       if (!data)
>> +               return -EINVAL;
>> +
>> +       base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
>> +       if (IS_ERR(base))
>> +               return PTR_ERR(base);
>> +
>> +       memcpy(&regmap_cfg, &base_clkc_regmap_cfg, sizeof(regmap_cfg));
>> +       regmap_cfg.max_register = resource_size(res) - 4;
>> +
>> +       map = devm_regmap_init_mmio(dev, base, &regmap_cfg);
>> +       if (IS_ERR(map))
>> +               return PTR_ERR(map);
>> +
>> +       return meson_clkc_init(dev, map);
>> +}
>> +EXPORT_SYMBOL_NS_GPL(meson_clkc_mmio_probe, "CLK_MESON");
>> +
>>   MODULE_DESCRIPTION("Amlogic Clock Controller Utilities");
>>   MODULE_LICENSE("GPL");
>>   MODULE_IMPORT_NS("CLK_MESON");
>> diff --git a/drivers/clk/meson/meson-clkc-utils.h b/drivers/clk/meson/meson-clkc-utils.h
>> index 26cd47544302b28ca1a342e178956559a84b152a..b45f85f630d7190fb6509b088f05f17ca91fa1c8 100644
>> --- a/drivers/clk/meson/meson-clkc-utils.h
>> +++ b/drivers/clk/meson/meson-clkc-utils.h
>> @@ -25,5 +25,6 @@ struct meson_clkc_data {
>>   };
>>
>>   int meson_clkc_syscon_probe(struct platform_device *pdev);
>> +int meson_clkc_mmio_probe(struct platform_device *pdev);
>>
>>   #endif
>>
>> --
>> 2.47.2
>>
>>
>> _______________________________________________
>> linux-amlogic mailing list
>> linux-amlogic at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-amlogic

-- 
Jerome



More information about the linux-amlogic mailing list