]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
soc: mediatek: mtk-dvfsrc: Rework bandwidth calculations
authorNicolas Frattaroli <nicolas.frattaroli@collabora.com>
Mon, 24 Nov 2025 11:06:59 +0000 (12:06 +0100)
committerAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Thu, 8 Jan 2026 09:27:50 +0000 (10:27 +0100)
commit3da293d70005496317d1ff3a49b89c29dd7c21e8
tree05566f5b6d8cbd07eae3774c99c02bd4e9f51020
parent39aa8c4e762ea9b00d66cc55957527167ed89435
soc: mediatek: mtk-dvfsrc: Rework bandwidth calculations

The code, as it is, plays fast and loose with bandwidth units. It also
doesn't specify its constraints in the actual maximum hardware value,
but as some roundabout thing that then ends up multiplied into the
actual hardware value constraint after some indirections. In part, this
is due to the use of individual members for storing each limit, instead
of making it possible to index them by type.

Rework all of this by adding const array members indexed by the
bandwidth type enum to the soc_data struct. This array expresses the
actual hardware value limitations, not a factor thereof.

Use the clamp function macro to clamp the values between the minimum and
maximum constraints after all the calculations, which also means the
code doesn't write nonsense to a hardware register when the math is
wrong, as it'll constrain after all the calculations.

Pass the type as the actual enum type as well, and not as an int. If
there's some type checking that can be extracted from the function
signature, then we may as well use it.

Don't needlessly explicitly cast return values to the return type
either; this is both unnecessary and makes it harder to spot type safety
issues.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
drivers/soc/mediatek/mtk-dvfsrc.c