Skip to content

Commit ae3e19c

Browse files
Chuan Liusuperna9999
authored andcommitted
soc: amlogic: clk-measure: Optimize the memory size of clk-measure
Drop "CLK_MSR_MAX" and replace it with adding a member "msr_count" in the structure to specify the count of msr_id. Mark the table of msr_id as const. Signed-off-by: Chuan Liu <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Link: https://lore.kernel.org/r/20250205-optimize_memory_size_of_clk_measure-v2-1-4f546053495d@amlogic.com Signed-off-by: Neil Armstrong <[email protected]>
1 parent 0af2f6b commit ae3e19c

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

drivers/soc/amlogic/meson-clk-measure.c

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,26 @@ static DEFINE_MUTEX(measure_lock);
3333
#define DIV_STEP 32
3434
#define DIV_MAX 640
3535

36-
#define CLK_MSR_MAX 128
37-
3836
struct meson_msr_id {
3937
struct meson_msr *priv;
4038
unsigned int id;
4139
const char *name;
4240
};
4341

42+
struct meson_msr_data {
43+
struct meson_msr_id *msr_table;
44+
unsigned int msr_count;
45+
};
46+
4447
struct meson_msr {
4548
struct regmap *regmap;
46-
struct meson_msr_id msr_table[CLK_MSR_MAX];
49+
struct meson_msr_data data;
4750
};
4851

4952
#define CLK_MSR_ID(__id, __name) \
5053
[__id] = {.id = __id, .name = __name,}
5154

52-
static struct meson_msr_id clk_msr_m8[CLK_MSR_MAX] = {
55+
static const struct meson_msr_id clk_msr_m8[] = {
5356
CLK_MSR_ID(0, "ring_osc_out_ee0"),
5457
CLK_MSR_ID(1, "ring_osc_out_ee1"),
5558
CLK_MSR_ID(2, "ring_osc_out_ee2"),
@@ -98,7 +101,7 @@ static struct meson_msr_id clk_msr_m8[CLK_MSR_MAX] = {
98101
CLK_MSR_ID(63, "mipi_csi_cfg"),
99102
};
100103

101-
static struct meson_msr_id clk_msr_gx[CLK_MSR_MAX] = {
104+
static const struct meson_msr_id clk_msr_gx[] = {
102105
CLK_MSR_ID(0, "ring_osc_out_ee_0"),
103106
CLK_MSR_ID(1, "ring_osc_out_ee_1"),
104107
CLK_MSR_ID(2, "ring_osc_out_ee_2"),
@@ -168,7 +171,7 @@ static struct meson_msr_id clk_msr_gx[CLK_MSR_MAX] = {
168171
CLK_MSR_ID(82, "ge2d"),
169172
};
170173

171-
static struct meson_msr_id clk_msr_axg[CLK_MSR_MAX] = {
174+
static const struct meson_msr_id clk_msr_axg[] = {
172175
CLK_MSR_ID(0, "ring_osc_out_ee_0"),
173176
CLK_MSR_ID(1, "ring_osc_out_ee_1"),
174177
CLK_MSR_ID(2, "ring_osc_out_ee_2"),
@@ -242,7 +245,7 @@ static struct meson_msr_id clk_msr_axg[CLK_MSR_MAX] = {
242245
CLK_MSR_ID(109, "audio_locker_in"),
243246
};
244247

245-
static struct meson_msr_id clk_msr_g12a[CLK_MSR_MAX] = {
248+
static const struct meson_msr_id clk_msr_g12a[] = {
246249
CLK_MSR_ID(0, "ring_osc_out_ee_0"),
247250
CLK_MSR_ID(1, "ring_osc_out_ee_1"),
248251
CLK_MSR_ID(2, "ring_osc_out_ee_2"),
@@ -358,7 +361,7 @@ static struct meson_msr_id clk_msr_g12a[CLK_MSR_MAX] = {
358361
CLK_MSR_ID(122, "audio_pdm_dclk"),
359362
};
360363

361-
static struct meson_msr_id clk_msr_sm1[CLK_MSR_MAX] = {
364+
static const struct meson_msr_id clk_msr_sm1[] = {
362365
CLK_MSR_ID(0, "ring_osc_out_ee_0"),
363366
CLK_MSR_ID(1, "ring_osc_out_ee_1"),
364367
CLK_MSR_ID(2, "ring_osc_out_ee_2"),
@@ -489,7 +492,7 @@ static struct meson_msr_id clk_msr_sm1[CLK_MSR_MAX] = {
489492
};
490493

491494
static int meson_measure_id(struct meson_msr_id *clk_msr_id,
492-
unsigned int duration)
495+
unsigned int duration)
493496
{
494497
struct meson_msr *priv = clk_msr_id->priv;
495498
unsigned int val;
@@ -573,13 +576,14 @@ DEFINE_SHOW_ATTRIBUTE(clk_msr);
573576
static int clk_msr_summary_show(struct seq_file *s, void *data)
574577
{
575578
struct meson_msr_id *msr_table = s->private;
579+
unsigned int msr_count = msr_table->priv->data.msr_count;
576580
unsigned int precision = 0;
577581
int val, i;
578582

579583
seq_puts(s, " clock rate precision\n");
580584
seq_puts(s, "---------------------------------------------\n");
581585

582-
for (i = 0 ; i < CLK_MSR_MAX ; ++i) {
586+
for (i = 0 ; i < msr_count ; ++i) {
583587
if (!msr_table[i].name)
584588
continue;
585589

@@ -604,7 +608,7 @@ static const struct regmap_config meson_clk_msr_regmap_config = {
604608

605609
static int meson_msr_probe(struct platform_device *pdev)
606610
{
607-
const struct meson_msr_id *match_data;
611+
const struct meson_msr_data *match_data;
608612
struct meson_msr *priv;
609613
struct dentry *root, *clks;
610614
void __iomem *base;
@@ -621,7 +625,16 @@ static int meson_msr_probe(struct platform_device *pdev)
621625
return -ENODEV;
622626
}
623627

624-
memcpy(priv->msr_table, match_data, sizeof(priv->msr_table));
628+
priv->data.msr_table = devm_kcalloc(&pdev->dev,
629+
match_data->msr_count,
630+
sizeof(struct meson_msr_id),
631+
GFP_KERNEL);
632+
if (!priv->data.msr_table)
633+
return -ENOMEM;
634+
635+
memcpy(priv->data.msr_table, match_data->msr_table,
636+
match_data->msr_count * sizeof(struct meson_msr_id));
637+
priv->data.msr_count = match_data->msr_count;
625638

626639
base = devm_platform_ioremap_resource(pdev, 0);
627640
if (IS_ERR(base))
@@ -636,45 +649,70 @@ static int meson_msr_probe(struct platform_device *pdev)
636649
clks = debugfs_create_dir("clks", root);
637650

638651
debugfs_create_file("measure_summary", 0444, root,
639-
priv->msr_table, &clk_msr_summary_fops);
652+
priv->data.msr_table, &clk_msr_summary_fops);
640653

641-
for (i = 0 ; i < CLK_MSR_MAX ; ++i) {
642-
if (!priv->msr_table[i].name)
654+
for (i = 0 ; i < priv->data.msr_count ; ++i) {
655+
if (!priv->data.msr_table[i].name)
643656
continue;
644657

645-
priv->msr_table[i].priv = priv;
658+
priv->data.msr_table[i].priv = priv;
646659

647-
debugfs_create_file(priv->msr_table[i].name, 0444, clks,
648-
&priv->msr_table[i], &clk_msr_fops);
660+
debugfs_create_file(priv->data.msr_table[i].name, 0444, clks,
661+
&priv->data.msr_table[i], &clk_msr_fops);
649662
}
650663

651664
return 0;
652665
}
653666

667+
static const struct meson_msr_data clk_msr_gx_data = {
668+
.msr_table = (void *)clk_msr_gx,
669+
.msr_count = ARRAY_SIZE(clk_msr_gx),
670+
};
671+
672+
static const struct meson_msr_data clk_msr_m8_data = {
673+
.msr_table = (void *)clk_msr_m8,
674+
.msr_count = ARRAY_SIZE(clk_msr_m8),
675+
};
676+
677+
static const struct meson_msr_data clk_msr_axg_data = {
678+
.msr_table = (void *)clk_msr_axg,
679+
.msr_count = ARRAY_SIZE(clk_msr_axg),
680+
};
681+
682+
static const struct meson_msr_data clk_msr_g12a_data = {
683+
.msr_table = (void *)clk_msr_g12a,
684+
.msr_count = ARRAY_SIZE(clk_msr_g12a),
685+
};
686+
687+
static const struct meson_msr_data clk_msr_sm1_data = {
688+
.msr_table = (void *)clk_msr_sm1,
689+
.msr_count = ARRAY_SIZE(clk_msr_sm1),
690+
};
691+
654692
static const struct of_device_id meson_msr_match_table[] = {
655693
{
656694
.compatible = "amlogic,meson-gx-clk-measure",
657-
.data = (void *)clk_msr_gx,
695+
.data = &clk_msr_gx_data,
658696
},
659697
{
660698
.compatible = "amlogic,meson8-clk-measure",
661-
.data = (void *)clk_msr_m8,
699+
.data = &clk_msr_m8_data,
662700
},
663701
{
664702
.compatible = "amlogic,meson8b-clk-measure",
665-
.data = (void *)clk_msr_m8,
703+
.data = &clk_msr_m8_data,
666704
},
667705
{
668706
.compatible = "amlogic,meson-axg-clk-measure",
669-
.data = (void *)clk_msr_axg,
707+
.data = &clk_msr_axg_data,
670708
},
671709
{
672710
.compatible = "amlogic,meson-g12a-clk-measure",
673-
.data = (void *)clk_msr_g12a,
711+
.data = &clk_msr_g12a_data,
674712
},
675713
{
676714
.compatible = "amlogic,meson-sm1-clk-measure",
677-
.data = (void *)clk_msr_sm1,
715+
.data = &clk_msr_sm1_data,
678716
},
679717
{ /* sentinel */ }
680718
};

0 commit comments

Comments
 (0)