Add an interface to get current DDR data rate
Subsystems (3)
v4 cover Add an interface to get current DDR data rate
This series is based on linux-next, tag: next-20250402.
Vcore DVFS feature need know the current DDR data rate. Add MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
---
Changes in v4:
- Rename "mediatek,dramc.yaml" to "mediatek,mt8196-dramc.yaml";
- Refine Kconfig for MediaTek memory controller by removing the redundant explanation;
- Move the function 'read_reg_field()' to before mtk_dramc_probe();
- Rename struct 'mtk_dramc_dev_t' to 'mtk_dramc';
- Align the comments to kerneldoc;
- Simplify the function 'mtk_dramc_get_data_rate' by removing the redundant error handling process.
---
Changes in v3:
- Move register offset, register mask and other SoC-dependent variables to the platform data;
- Correct the spelling error.
Link to v3:
https://patchwork.kernel.org/patch/14029756
---
Changes in v2:
- Remove pr_info and pr_err, use dev_err or dev_err_probe to print error message;
- Replace module_init by module_platform_driver;
- Remove unnecessary global variables;
- Change fmeter-verison to platform data;
- Remove mtk-dramc.h;
- Refine compatible to "mediatek,mt8196-dramc";
- Refine CONFIG name to MEDIATEK_MC;
- Fix yaml build errors, remove unnecessary properties on yaml file.
Link to v2:
https://patchwork.kernel.org/patch/13964208
Crystal Guo (2):
dt-bindings: memory-controllers: Add MediaTek DRAM controller
interface
memory/mediatek: Add an interface to get current DDR data rate
.../mediatek,mt8196-dramc.yaml | 44 ++++ drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/mediatek/Kconfig | 20 ++ drivers/memory/mediatek/Makefile | 2 + drivers/memory/mediatek/mtk-dramc.c | 223 ++++++++++++++++++ 6 files changed, 291 insertions(+) create mode 100644 Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml create mode 100644 drivers/memory/mediatek/Kconfig create mode 100644 drivers/memory/mediatek/Makefile create mode 100644 drivers/memory/mediatek/mtk-dramc.c
Signature · 1 line
2.18.0
PATCH v4 1/2 dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
A MediaTek DRAM controller interface to provide the current DDR data rate.
--- .../mediatek,mt8196-dramc.yaml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +44 -0
@@ -0,0 +1,44 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (c) 2025 MediaTek Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/memory-controllers/mediatek,mt8196-dramc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek DRAM Controller (DRAMC) + +maintainers: + - Crystal Guo <[email protected]> + +description: + A MediaTek DRAM controller interface to provide the current data rate of DRAM. + +properties: + compatible: + items: + - enum: + - mediatek,mt8196-dramc + + reg: + items: + - description: anaphy registers + - description: ddrphy registers + +additionalProperties: false + +required: + - compatible + - reg + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + memory-controller@10236000 { + compatible = "mediatek,mt8196-dramc"; + reg = <0 0x10236000 0 0x2000>, + <0 0x10238000 0 0x2000>; + }; + };
Signature · 1 line
2.18.0
Re: [PATCH v4 1/2] dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
Il 03/04/25 08:48, Crystal Guo ha scritto:
Quoted 4 lines
A MediaTek DRAM controller interface to provide the current DDR data rate.
Signed-off-by Crystal Guo <[email protected]>
Krzysztof Kozlowski
maintainerRe: [PATCH v4 1/2] dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
In reply to Crystal GuoDocumentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml line 14
Quoted 5 lines · Crystal Guo
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +5
-0+maintainers: + - Crystal Guo <[email protected]> + +description: + A MediaTek DRAM controller interface to provide the current data rate of DRAM.
DRAM controller does not offer scaling? Or PHY/timing configuration? This binding looks pretty incomplete.
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml line 27
Quoted 13 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +13
-0+ +properties: + compatible: + items: + - enum: + - mediatek,mt8196-dramc + + reg: + items: + - description: anaphy registers + - description: ddrphy registers + +additionalProperties: false
If there is going to be any resend then this goes after required: block.
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml line 31
Quoted 4 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +4
-0+ +required: + - compatible + - reg
Best regards,
Krzysztof
Re: [PATCH v4 1/2] dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
Quoted 5 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
On Thu, Apr 03, 2025 at 02:48:47PM GMT, Crystal Guo wrote:
Quoted 10 lines
Quoted 6 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +5
-0+maintainers: + - Crystal Guo <[email protected]> + +description: + A MediaTek DRAM controller interface to provide the current datarate of DRAM.
DRAM controller does not offer scaling? Or PHY/timing configuration? This binding looks pretty incomplete.
The PHY/timing configuration is completed during the bootloader stage. In the kernel, we currently only need to provide an interface to retrieve the current DDR data rate.
Quoted 17 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml line 27
Quoted 13 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +13
-0+ +properties: + compatible: + items: + - enum: + - mediatek,mt8196-dramc + + reg: + items: + - description: anaphy registers + - description: ddrphy registers + +additionalProperties: falseIf there is going to be any resend then this goes after required:
block.
Quoted 8 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml line 31
Quoted 4 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +4
-0+ +required: + - compatible + - regBest regards,
Krzysztof
Okay, thanks for the suggestion.
I will adjust the order in the next version.
Best regards,
Crystal Guo
Krzysztof Kozlowski
maintainerRe: [PATCH v4 1/2] dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
Quoted 17 lines · Crystal Guo (郭晶)
Quoted 5 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
On Thu, Apr 03, 2025 at 02:48:47PM GMT, Crystal Guo wrote:
Quoted 10 lines
Quoted 6 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +5
-0+maintainers: + - Crystal Guo <[email protected]> + +description: + A MediaTek DRAM controller interface to provide the current datarate of DRAM.
DRAM controller does not offer scaling? Or PHY/timing configuration? This binding looks pretty incomplete.
Quoted 3 lines
The PHY/timing configuration is completed during the bootloader stage. In the kernel, we currently only need to provide an interface to retrieve the current DDR data rate.
Not really, that's what you currently want to do in kernel, but not what you for example will want next days. Binding is supposed to be complete, so if you do not have any scaling/interconnect then extend the description of hardware and explain that memory controller is non configurable, cannot scale and it exposes only read interface. Or something similar.
Best regards,
Krzysztof
Re: [PATCH v4 1/2] dt-bindings: memory-controllers: Add MediaTek DRAM controller interface
Quoted 39 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 20 lines · Crystal Guo (郭晶)
Quoted 6 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until
you have verified the sender or the content.On Thu, Apr 03, 2025 at 02:48:47PM GMT, Crystal Guo wrote:
Quoted 12 lines
Quoted 7 lines
Documentation/devicetree/bindings/memory-controllers/mediatek,mt8196-dramc.yaml new file +5
-0+maintainers: + - Crystal Guo <[email protected]> + +description: + A MediaTek DRAM controller interface to provide the currentdata
rate of DRAM.DRAM controller does not offer scaling? Or PHY/timing configuration?
This binding looks pretty incomplete.Quoted 4 lines
The PHY/timing configuration is completed during the bootloader stage.
In the kernel, we currently only need to provide an interface to retrieve the current DDR data rate.Not really, that's what you currently want to do in kernel, but not what
you for example will want next days. Binding is supposed to be complete,
so if you do not have any scaling/interconnect then extend the description of hardware and explain that memory controller is non configurable, cannot scale and it exposes only read interface. Or something similar.
Quoted 2 lines
Best regards,
Krzysztof
Okay, the following instructions will be added in the next version:
'A MediaTek DRAM controller interface that provides the current data rate of DRAM.
This controller is designed solely to provide a read interface for retrieving the DDR data rate. It does not support scaling or PHY/timing configuration during the kernel stage, as these configurations are already completed during the bootloader stage.'
Best regards,
Crystal Guo
PATCH v4 2/2 memory/mediatek: Add an interface to get current DDR data rate
In reply to Crystal GuoAdd MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
--- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/mediatek/Kconfig | 20 +++ drivers/memory/mediatek/Makefile | 2 + drivers/memory/mediatek/mtk-dramc.c | 223 ++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 drivers/memory/mediatek/Kconfig create mode 100644 drivers/memory/mediatek/Makefile create mode 100644 drivers/memory/mediatek/mtk-dramc.c
drivers/memory/Kconfig +1 -0
@@ -227,5 +227,6 @@ config STM32_FMC2_EBI source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/mediatek/Kconfig" endif
drivers/memory/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o obj-$(CONFIG_SAMSUNG_MC) += samsung/ obj-$(CONFIG_TEGRA_MC) += tegra/ +obj-$(CONFIG_MEDIATEK_MC) += mediatek/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.o
drivers/memory/mediatek/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MEDIATEK_MC + bool "MediaTek Memory Controller support" + default y + depends on ARCH_MEDIATEK || COMPILE_TEST + help + This option allows to enable MediaTek memory controller drivers, + which may include controllers for DRAM or others. + +if MEDIATEK_MC + +config MTK_DRAMC + tristate "MediaTek DRAMC driver" + default y + help + This driver is for the DRAM Controller found in MediaTek SoCs + and provides a sysfs interface for reporting the current DRAM + data rate. + +endif
drivers/memory/mediatek/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_MTK_DRAMC) += mtk-dramc.o
drivers/memory/mediatek/mtk-dramc.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [PATCH v4 2/2] memory/mediatek: Add an interface to get current DDR data rate
Il 03/04/25 08:48, Crystal Guo ha scritto:
Quoted 4 lines
Add MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
Signed-off-by Crystal Guo <[email protected]>
Krzysztof Kozlowski
maintainerRe: [PATCH v4 2/2] memory/mediatek: Add an interface to get current DDR data rate
In reply to Crystal GuoPlease use subject prefixes matching the subsystem. You can get them for example with 'git log --oneline -- DIRECTORY_OR_FILE' on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters
memory: mediatek:
Quoted 20 lines · Crystal Guo
Add MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
Signed-off-by Crystal Guo <[email protected]>--- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/mediatek/Kconfig | 20 +++ drivers/memory/mediatek/Makefile | 2 + drivers/memory/mediatek/mtk-dramc.c | 223 ++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 drivers/memory/mediatek/Kconfig create mode 100644 drivers/memory/mediatek/Makefile create mode 100644 drivers/memory/mediatek/mtk-dramc.cdrivers/memory/Kconfig +0
-0
drivers/memory/Kconfig config STM32_FMC2_EBI · line 230
Quoted 4 lines
drivers/memory/Kconfig +1
-0@@ -227,5 +227,6 @@ config STM32_FMC2_EBI source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/mediatek/Kconfig"
m goes before s, so this goes before samsung source.
Quoted 20 lines
drivers/memory/Kconfig +0
-0endifdrivers/memory/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o obj-$(CONFIG_SAMSUNG_MC) += samsung/ obj-$(CONFIG_TEGRA_MC) += tegra/ +obj-$(CONFIG_MEDIATEK_MC) += mediatek/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.odrivers/memory/mediatek/Kconfig new file +0
-0
drivers/memory/mediatek/Kconfig line 4
Quoted 4 lines
drivers/memory/mediatek/Kconfig new file +4
-0@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MEDIATEK_MC + bool "MediaTek Memory Controller support" + default y
Why this has to be enabled for every compile test build? Look how other platforms do it.
I'll fix the tegra.
drivers/memory/mediatek/Kconfig line 14
Quoted 10 lines
drivers/memory/mediatek/Kconfig new file +10
-0+ depends on ARCH_MEDIATEK || COMPILE_TEST + help + This option allows to enable MediaTek memory controller drivers, + which may include controllers for DRAM or others. + +if MEDIATEK_MC + +config MTK_DRAMC + tristate "MediaTek DRAMC driver" + default y
This matters less, could stay or could be also ARCH_MDIATEK.
Quoted 6 lines
drivers/memory/mediatek/Kconfig new file +6
-0+ help + This driver is for the DRAM Controller found in MediaTek SoCs + and provides a sysfs interface for reporting the current DRAM + data rate. + +endif
...
drivers/memory/mediatek/Kconfig
Quoted 10 lines
drivers/memory/mediatek/Kconfig new file +10
-0+ +static unsigned int read_reg_field(void __iomem *base, unsigned int offset, unsigned int mask) +{ + unsigned int val = readl(base + offset); + unsigned int shift = __ffs(mask); + + return (val & mask) >> shift; +} + +static int mtk_dramc_probe(struct platform_device *pdev)
Weird ordering. probe() is one of the last functions. Only other driver struct functions (like remove, suspend/resume) go after, not some regular code.
drivers/memory/mediatek/Kconfig
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +11
-0+{ + struct mtk_dramc *dramc; + const struct mtk_dramc_pdata *pdata; + + dramc = devm_kzalloc(&pdev->dev, sizeof(struct mtk_dramc), GFP_KERNEL); + if (!dramc) + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed to allocate memory\n"); + + pdata = of_device_get_match_data(&pdev->dev); + if (!pdata) + return dev_err_probe(&pdev->dev, -EINVAL, "No platform data available\n");
Just return. That's impossible condition, so no need for printing errors.
drivers/memory/mediatek/Kconfig
Quoted 2 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ + dramc->pdata = pdata;
Why do you need pdata variable in the first place? Make this code simple, not complicated.
Quoted 15 lines
drivers/memory/mediatek/Kconfig new file +15
-0+ + dramc->anaphy_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(dramc->anaphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc->anaphy_base), + "Unable to map ANAPHY base\n"); + + dramc->ddrphy_base = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(dramc->ddrphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc->ddrphy_base), + "Unable to map DDRPHY base\n"); + + platform_set_drvdata(pdev, dramc); + return 0; +} +
drivers/memory/mediatek/Kconfig
Quoted 10 lines
drivers/memory/mediatek/Kconfig new file +10
-0+static unsigned int mtk_fmeter_v1(struct mtk_dramc *dramc) +{ + const struct mtk_dramc_pdata *pdata = dramc->pdata; + unsigned int shu_level, pll_sel, offset; + unsigned int sdmpcw, posdiv, clkdiv, fbksel, sopen, async_ca, ser_mode; + unsigned int prediv_freq, posdiv_freq, vco_freq; + unsigned int final_rate; + + shu_level = read_reg_field(dramc->ddrphy_base, pdata->regs[DRAMC_DPHY_DVFS_STA], + pdata->masks[DRAMC_DPHY_DVFS_SHU_LV]);
Don't creat your own wrappers. Use existing FIELD_PREP stuff.
Quoted 38 lines
drivers/memory/mediatek/Kconfig new file +38
-0+ pll_sel = read_reg_field(dramc->ddrphy_base, pdata->regs[DRAMC_DPHY_DVFS_STA], + pdata->masks[DRAMC_DPHY_DVFS_PLL_SEL]); + offset = pdata->shuffle_offset * shu_level; + + sdmpcw = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL2] : + pdata->regs[DRAMC_APHY_SHU_CLRPLL2]) + offset, + pdata->masks[DRAMC_APHY_PLL2_SDMPCW]); + posdiv = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL3] : + pdata->regs[DRAMC_APHY_SHU_CLRPLL3]) + offset, + pdata->masks[DRAMC_APHY_PLL3_POSDIV]); + fbksel = read_reg_field(dramc->anaphy_base, pdata->regs[DRAMC_APHY_SHU_PHYPLL4] + offset, + pdata->masks[DRAMC_APHY_PLL4_FBKSEL]); + sopen = read_reg_field(dramc->anaphy_base, pdata->regs[DRAMC_APHY_ARPI0] + offset, + pdata->masks[DRAMC_APHY_ARPI0_SOPEN]); + async_ca = read_reg_field(dramc->anaphy_base, pdata->regs[DRAMC_APHY_CA_ARDLL1] + offset, + pdata->masks[DRAMC_APHY_ARDLL1_CK_EN]); + ser_mode = read_reg_field(dramc->anaphy_base, pdata->regs[DRAMC_APHY_B0_TX0] + offset, + pdata->masks[DRAMC_APHY_B0_TX0_SER_MODE]); + + clkdiv = (ser_mode == 1) ? 1 : 0; + posdiv &= ~(pdata->posdiv_purify); + + prediv_freq = pdata->ref_freq_mhz * (sdmpcw >> pdata->prediv); + posdiv_freq = (prediv_freq >> posdiv) >> 1; + vco_freq = posdiv_freq << fbksel; + final_rate = vco_freq >> clkdiv; + + if (sopen == 1 && async_ca == 1) + final_rate >>= 1; + + return final_rate; +} + +/**
drivers/memory/mediatek/Kconfig
Quoted 10 lines
drivers/memory/mediatek/Kconfig new file +10
-0+ * mtk_dramc_get_data_rate - Calculate the current DRAM data rate + * @dev: Device pointer + * + * Return: DRAM Data Rate in Mbps or negative number for error + */ +static unsigned int mtk_dramc_get_data_rate(struct device *dev) +{ + struct mtk_dramc *dramc = dev_get_drvdata(dev); + + if (dramc->pdata->fmeter_version == 1)
Drop, it's not possible to have other case.
drivers/memory/mediatek/Kconfig
Quoted 8 lines
drivers/memory/mediatek/Kconfig new file +8
-0+ return mtk_fmeter_v1(dramc); + + dev_err(dev, "Frequency meter version %u not supported\n", dramc->pdata->fmeter_version); + return -EINVAL; +} + +static ssize_t dram_data_rate_show(struct device *dev, + struct device_attribute *attr, char *buf)
No ABI doc.
Why existing interconnect interface is not suitable here? This should be an interconnect, otherwise what is the point of this driver? What do you exactly configure here?
Quoted 45 lines
drivers/memory/mediatek/Kconfig new file +42
-0+{ + return snprintf(buf, PAGE_SIZE, "DRAM data rate = %u\n", + mtk_dramc_get_data_rate(dev)); +} + +static DEVICE_ATTR_RO(dram_data_rate); + +static struct attribute *mtk_dramc_attrs[] = { + &dev_attr_dram_data_rate.attr, + NULL +}; +ATTRIBUTE_GROUPS(mtk_dramc); + +static const struct mtk_dramc_pdata dramc_pdata_mt8196 = { + .fmeter_version = 1, + .ref_freq_mhz = 26, + .regs = mtk_dramc_regs_mt8196, + .masks = mtk_dramc_masks_mt8196, + .posdiv_purify = BIT(2), + .prediv = 7, + .shuffle_offset = 0x700, +}; + +static const struct of_device_id mtk_dramc_of_ids[] = { + { .compatible = "mediatek,mt8196-dramc", .data = &dramc_pdata_mt8196 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mtk_dramc_of_ids); + +static struct platform_driver mtk_dramc_driver = { + .probe = mtk_dramc_probe, + .driver = { + .name = "mtk-dramc", + .of_match_table = mtk_dramc_of_ids, + .dev_groups = mtk_dramc_groups, + }, +}; +module_platform_driver(mtk_dramc_driver); + +MODULE_AUTHOR("Crystal Guo <[email protected]>"); +MODULE_DESCRIPTION("MediaTek DRAM Controller Driver"); +MODULE_LICENSE("GPL");Signature · 1 line
2.18.0
Re: [PATCH v4 2/2] memory/mediatek: Add an interface to get current DDR data rate
Quoted 11 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Please use subject prefixes matching the subsystem. You can get them for
example with 'git log --oneline --DIRECTORY_OR_FILE' on the directory
your patch is touching. For bindings, the preferred subjects are explained here:
Quoted 2 lines
memory: mediatek:
Thanks for the suggestion, I will use the correct subject prefixes in the next version:
'memory: mediatek: Add an interface to get current DDR data rate'
Quoted 24 lines · Crystal Guo
Quoted 22 lines
Add MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
Signed-off-by Crystal Guo <[email protected]>--- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/mediatek/Kconfig | 20 +++ drivers/memory/mediatek/Makefile | 2 + drivers/memory/mediatek/mtk-dramc.c | 223 ++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 drivers/memory/mediatek/Kconfig create mode 100644 drivers/memory/mediatek/Makefile create mode 100644 drivers/memory/mediatek/mtk-dramc.cdrivers/memory/Kconfig +0
-0@@ -227,5 +227,6 @@ config STM32_FMC2_EBI
Quoted 6 lines
drivers/memory/Kconfig config STM32_FMC2_EBI · line 230
Quoted 3 lines
drivers/memory/Kconfig +1
-0source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/mediatek/Kconfig"m goes before s, so this goes before samsung source.
Okay, I will update it in the next version.
Quoted 31 lines
Quoted 22 lines
drivers/memory/Kconfig +0
-0endifdrivers/memory/Makefile +0
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
obj-$(CONFIG_SAMSUNG_MC) += samsung/
obj-$(CONFIG_TEGRA_MC) += tegra/drivers/memory/Makefile +1
-0+obj-$(CONFIG_MEDIATEK_MC) += mediatek/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.odrivers/memory/mediatek/Kconfig new file +0
-0drivers/memory/mediatek/Kconfig line 4
Quoted 4 lines
drivers/memory/mediatek/Kconfig new file +4
-0@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MEDIATEK_MC + bool "MediaTek Memory Controller support" + default yWhy this has to be enabled for every compile test build? Look how other
platforms do it.
Quoted 2 lines
I'll fix the tegra.
Okay, I will change 'default Y' to 'default ARCH_MEDIATEK' in the next version.
Quoted 15 lines
drivers/memory/mediatek/Kconfig line 14
Quoted 12 lines
drivers/memory/mediatek/Kconfig new file +3
-0+ depends on ARCH_MEDIATEK || COMPILE_TEST + help + This option allows to enable MediaTek memory controllerdrivers,
drivers/memory/mediatek/Kconfig new file +7
-0+ which may include controllers for DRAM or others. + +if MEDIATEK_MC + +config MTK_DRAMC + tristate "MediaTek DRAMC driver" + default yThis matters less, could stay or could be also
ARCH_MDIATEK.
Understood, I will keep this part unchanged in the next version. Thank you for your suggestion.
Quoted 11 lines
Quoted 8 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ help + This driver is for the DRAM Controller found in MediaTekSoCs
+ and provides a sysfs interface for reporting the current
DRAMdrivers/memory/mediatek/Kconfig new file +3
-0+ data rate. + +endif...
Quoted 16 lines
drivers/memory/mediatek/Kconfig
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ +static unsigned int read_reg_field(void __iomem *base, unsignedint offset, unsigned int mask)
drivers/memory/mediatek/Kconfig new file +8
-0+{ + unsigned int val = readl(base + offset); + unsigned int shift = __ffs(mask); + + return (val & mask) >> shift; +} + +static int mtk_dramc_probe(struct platform_device *pdev)Weird ordering.
probe()is one of the last functions. Only other driver
struct functions (like remove, suspend/resume) go after, not some regular code.
Understood. I will adjust the order of the probe function in the next version.
Quoted 10 lines
Quoted 10 lines
drivers/memory/mediatek/Kconfig new file +5
-0+{ + struct mtk_dramc *dramc; + const struct mtk_dramc_pdata *pdata; + + dramc = devm_kzalloc(&pdev->dev, sizeof(struct mtk_dramc),
GFP_KERNEL);drivers/memory/mediatek/Kconfig new file +2
-0+ if (!dramc) + return dev_err_probe(&pdev->dev, -ENOMEM, "Failed toallocate memory\n");
Quoted 8 lines
Quoted 5 lines
drivers/memory/mediatek/Kconfig new file +4
-0+ + pdata = of_device_get_match_data(&pdev->dev); + if (!pdata) + return dev_err_probe(&pdev->dev, -EINVAL, "Noplatform data available\n");
Just return. That's impossible condition, so no need for printing errors.
Okay, will return directly in the next version.
Quoted 6 lines
drivers/memory/mediatek/Kconfig
Quoted 3 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ + dramc->pdata = pdata;Why do you need pdata variable in the first place? Make this code simple, not complicated.
Okay, will remove redundant 'pdata' in the next version.
Quoted 28 lines
Quoted 28 lines
drivers/memory/mediatek/Kconfig new file +4
-0+ + dramc->anaphy_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(dramc->anaphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc-Quoted 1 line
anaphy_base),drivers/memory/mediatek/Kconfig new file +5
-0+ "Unable to map ANAPHY base\n"); + + dramc->ddrphy_base = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(dramc->ddrphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc-Quoted 1 line
ddrphy_base),drivers/memory/mediatek/Kconfig new file +11
-0+ "Unable to map DDRPHY base\n"); + + platform_set_drvdata(pdev, dramc); + return 0; +} + +static unsigned int mtk_fmeter_v1(struct mtk_dramc *dramc) +{ + const struct mtk_dramc_pdata *pdata = dramc->pdata; + unsigned int shu_level, pll_sel, offset; + unsigned int sdmpcw, posdiv, clkdiv, fbksel, sopen, async_ca,
ser_mode;drivers/memory/mediatek/Kconfig new file +4
-0+ unsigned int prediv_freq, posdiv_freq, vco_freq; + unsigned int final_rate; + + shu_level = read_reg_field(dramc->ddrphy_base, pdata-
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
regs[DRAMC_DPHY_DVFS_STA],
+ pdata-
Quoted 1 line
masks[DRAMC_DPHY_DVFS_SHU_LV]);
Don't creat your own wrappers. Use existing
FIELD_PREPstuff.
Since the mask is not a constant, using FIELD_GET will result in a compilation error. Can I keep using 'read_reg_field' in the next version?
Quoted 57 lines
Quoted 57 lines
+
pll_sel= read_reg_field(dramc->ddrphy_base, pdata-Quoted 1 line
regs[DRAMC_DPHY_DVFS_STA],
+ pdata-
Quoted 1 line
masks[DRAMC_DPHY_DVFS_PLL_SEL]);
drivers/memory/mediatek/Kconfig new file +8
-0+ offset = pdata->shuffle_offset * shu_level; + + sdmpcw = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL2] : + pdata->regs[DRAMC_APHY_SHU_CLRPLL2]) + offset, + pdata-Quoted 1 line
masks[DRAMC_APHY_PLL2_SDMPCW]);
drivers/memory/mediatek/Kconfig new file +6
-0+ posdiv = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL3] : + pdata->regs[DRAMC_APHY_SHU_CLRPLL3]) + offset, + pdata-Quoted 1 line
masks[DRAMC_APHY_PLL3_POSDIV]);
+ fbksel = read_reg_field(dramc->anaphy_base, pdata-
Quoted 1 line
regs[DRAMC_APHY_SHU_PHYPLL4] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_PLL4_FBKSEL]);
+ sopen = read_reg_field(dramc->anaphy_base, pdata-
Quoted 1 line
regs[DRAMC_APHY_ARPI0] + offset,
drivers/memory/mediatek/Kconfig new file +2
-0+ pdata->masks[DRAMC_APHY_ARPI0_SOPEN]); + async_ca = read_reg_field(dramc->anaphy_base, pdata-Quoted 1 line
regs[DRAMC_APHY_CA_ARDLL1] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_ARDLL1_CK_EN]);
+
ser_mode= read_reg_field(dramc->anaphy_base, pdata-Quoted 1 line
regs[DRAMC_APHY_B0_TX0] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_B0_TX0_SER_MODE]);
drivers/memory/mediatek/Kconfig new file +5
-0+ + clkdiv = (ser_mode == 1) ? 1 : 0; + posdiv &= ~(pdata->posdiv_purify); + + prediv_freq = pdata->ref_freq_mhz * (sdmpcw >> pdata-Quoted 1 line
prediv);
drivers/memory/mediatek/Kconfig new file +15
-0+ posdiv_freq = (prediv_freq >> posdiv) >> 1; + vco_freq = posdiv_freq << fbksel; + final_rate = vco_freq >> clkdiv; + + if (sopen == 1 && async_ca == 1) + final_rate >>= 1; + + return final_rate; +} + +/** + * mtk_dramc_get_data_rate - Calculate the current DRAM data rate + * @dev: Device pointer + * + * Return: DRAM Data Rate in Mbps or negative number for error
Quoted 8 lines
drivers/memory/mediatek/Kconfig
Quoted 6 lines
+ */
drivers/memory/mediatek/Kconfig new file +5
-0+static unsigned int mtk_dramc_get_data_rate(struct device *dev) +{ + struct mtk_dramc *dramc = dev_get_drvdata(dev); + + if (dramc->pdata->fmeter_version == 1)Drop, it's not possible to have other case.
Thank you for your suggestion.
In the future, other SoCs might use different fmeter version to calculate the DDR data rate. If we remove the fmeter_version now, future SoCs that cannot share mtk_fmeter_v1 will still need to add the fmeter_version variable.
Therefore, can I keep the current implementation for now.
Quoted 14 lines
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +3
-0+ return mtk_fmeter_v1(dramc); + + dev_err(dev, "Frequency meter version %u not supported\n",
dramc->pdata->fmeter_version);drivers/memory/mediatek/Kconfig new file +5
-0+ return -EINVAL; +} + +static ssize_t dram_data_rate_show(struct device *dev, + struct device_attribute *attr,char *buf)
No ABI doc.
Quoted 6 lines
Why existing interconnect interface is not suitable here? This should
be an interconnect, otherwise what is the point of this driver? What do
you exactly configure here?
This driver specifically focuses on displaying the current DDR data rate, which is used for the DVFS (Dynamic Voltage and Frequency Scaling) feature to verify that DDR frequency adjustments are correctly executed.
I will add the ABI documentation for the dram_data_rate attribute as follows, is this ok?
What: /sys/devices/platform/soc/XXXXXXXX.memory-
controller/dram_data_rate
Date: April 2025
KernelVersion: 6.14
Contact: Crystal Guo <[email protected]>
Description:
Reports the current DRAM data rate in Mbps.
Access: Read
Quoted 47 lines
Quoted 47 lines
drivers/memory/mediatek/Kconfig new file +25
-0+{ + return snprintf(buf, PAGE_SIZE, "DRAM data rate = %u\n", + mtk_dramc_get_data_rate(dev)); +} + +static DEVICE_ATTR_RO(dram_data_rate); + +static struct attribute *mtk_dramc_attrs[] = { + &dev_attr_dram_data_rate.attr, + NULL +}; +ATTRIBUTE_GROUPS(mtk_dramc); + +static const struct mtk_dramc_pdata dramc_pdata_mt8196 = { + .fmeter_version = 1, + .ref_freq_mhz = 26, + .regs = mtk_dramc_regs_mt8196, + .masks = mtk_dramc_masks_mt8196, + .posdiv_purify = BIT(2), + .prediv = 7, + .shuffle_offset = 0x700, +}; + +static const struct of_device_id mtk_dramc_of_ids[] = { + { .compatible = "mediatek,mt8196-dramc", .data =
&dramc_pdata_mt8196},drivers/memory/mediatek/Kconfig new file +17
-1+ { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mtk_dramc_of_ids); + +static struct platform_driver mtk_dramc_driver = { + .probe = mtk_dramc_probe, + .driver = { + .name = "mtk-dramc", + .of_match_table = mtk_dramc_of_ids, + .dev_groups = mtk_dramc_groups, + }, +}; +module_platform_driver(mtk_dramc_driver); + +MODULE_AUTHOR("Crystal Guo <[email protected]>"); +MODULE_DESCRIPTION("MediaTek DRAM Controller Driver"); +MODULE_LICENSE("GPL"); --2.18.0
Re: [PATCH v4 2/2] memory/mediatek: Add an interface to get current DDR data rate
Quoted 8 lines · crystal guo
Quoted 1 line
Quoted 5 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until
you have verified the sender or the content.
Quoted 10 lines
Quoted 8 lines
Please use subject prefixes matching the subsystem. You can get them
for
example with 'git log --oneline --DIRECTORY_OR_FILE' on the directory
your patch is touching. For bindings, the preferred subjects are explained here:
Quoted 335 lines
Quoted 2 lines
memory: mediatek:
Thanks for the suggestion, I will use the correct subject prefixes in the next version:
'memory: mediatek: Add an interface to get current DDR data rate'Quoted 24 lines · Crystal Guo
Quoted 22 lines
Add MediaTek DRAMC driver to provide an interface that can obtain current DDR data rate.
Signed-off-by Crystal Guo <[email protected]>--- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/mediatek/Kconfig | 20 +++ drivers/memory/mediatek/Makefile | 2 + drivers/memory/mediatek/mtk-dramc.c | 223 ++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 drivers/memory/mediatek/Kconfig create mode 100644 drivers/memory/mediatek/Makefile create mode 100644 drivers/memory/mediatek/mtk-dramc.cdrivers/memory/Kconfig +0
-0@@ -227,5 +227,6 @@ config STM32_FMC2_EBIQuoted 6 lines
drivers/memory/Kconfig config STM32_FMC2_EBI · line 230
Quoted 3 lines
drivers/memory/Kconfig +1
-0source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/mediatek/Kconfig"m goes before s, so this goes before samsung source.
Okay, I will update it in the next version.
Quoted 31 lines
Quoted 22 lines
drivers/memory/Kconfig +0
-0endifdrivers/memory/Makefile +0
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
obj-$(CONFIG_SAMSUNG_MC) += samsung/
obj-$(CONFIG_TEGRA_MC) += tegra/drivers/memory/Makefile +1
-0+obj-$(CONFIG_MEDIATEK_MC) += mediatek/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.odrivers/memory/mediatek/Kconfig new file +0
-0drivers/memory/mediatek/Kconfig line 4
Quoted 4 lines
drivers/memory/mediatek/Kconfig new file +4
-0@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MEDIATEK_MC + bool "MediaTek Memory Controller support" + default yWhy this has to be enabled for every compile test build? Look how other
platforms do it.Quoted 2 lines
I'll fix the tegra.
Okay, I will change 'default Y' to 'default
ARCH_MEDIATEK' in the next
version.Quoted 15 lines
drivers/memory/mediatek/Kconfig line 14
Quoted 12 lines
drivers/memory/mediatek/Kconfig new file +3
-0+ depends on ARCH_MEDIATEK || COMPILE_TEST + help + This option allows to enable MediaTek memory controllerdrivers,
drivers/memory/mediatek/Kconfig new file +7
-0+ which may include controllers for DRAM or others. + +if MEDIATEK_MC + +config MTK_DRAMC + tristate "MediaTek DRAMC driver" + default yThis matters less, could stay or could be also
ARCH_MDIATEK.Understood, I will keep this part unchanged in the next version. Thank you for your suggestion.
Quoted 11 lines
Quoted 8 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ help + This driver is for the DRAM Controller found in MediaTekSoCs
+ and provides a sysfs interface for reporting the current
DRAMdrivers/memory/mediatek/Kconfig new file +3
-0+ data rate. + +endif...
Quoted 16 lines
drivers/memory/mediatek/Kconfig
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ +static unsigned int read_reg_field(void __iomem *base, unsignedint offset, unsigned int mask)
drivers/memory/mediatek/Kconfig new file +8
-0+{ + unsigned int val = readl(base + offset); + unsigned int shift = __ffs(mask); + + return (val & mask) >> shift; +} + +static int mtk_dramc_probe(struct platform_device *pdev)Weird ordering.
probe()is one of the last functions. Only other driver
struct functions (like remove, suspend/resume) go after, not some regular code.Understood. I will adjust the order of the probe function in the next version.
Quoted 11 lines
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +5
-0+{ + struct mtk_dramc *dramc; + const struct mtk_dramc_pdata *pdata; + + dramc = devm_kzalloc(&pdev->dev, sizeof(struct mtk_dramc),
GFP_KERNEL);drivers/memory/mediatek/Kconfig new file +2
-0+ if (!dramc) + return dev_err_probe(&pdev->dev, -ENOMEM, "Failedto
allocate memory\n");Quoted 8 lines
Quoted 5 lines
drivers/memory/mediatek/Kconfig new file +4
-0+ + pdata = of_device_get_match_data(&pdev->dev); + if (!pdata) + return dev_err_probe(&pdev->dev, -EINVAL, "Noplatform data available\n");
Just return. That's impossible condition, so no need for printing errors.
Okay, will return directly in the next version.
Quoted 6 lines
drivers/memory/mediatek/Kconfig
Quoted 3 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ + dramc->pdata = pdata;Why do you need pdata variable in the first place? Make this code simple, not complicated.
Okay, will remove redundant 'pdata' in the next version.
Quoted 35 lines
Quoted 35 lines
drivers/memory/mediatek/Kconfig new file +2
-0+ + dramc->anaphy_base = devm_platform_ioremap_resource(pdev,0);
drivers/memory/mediatek/Kconfig new file +2
-0+ if (IS_ERR(dramc->anaphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc-Quoted 1 line
anaphy_base),+ "Unable to map ANAPHY
base\n");drivers/memory/mediatek/Kconfig new file +2
-0+ + dramc->ddrphy_base = devm_platform_ioremap_resource(pdev,1);
drivers/memory/mediatek/Kconfig new file +2
-0+ if (IS_ERR(dramc->ddrphy_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(dramc-Quoted 1 line
ddrphy_base),+ "Unable to map DDRPHY
base\n");drivers/memory/mediatek/Kconfig new file +10
-0+ + platform_set_drvdata(pdev, dramc); + return 0; +} + +static unsigned int mtk_fmeter_v1(struct mtk_dramc *dramc) +{ + const struct mtk_dramc_pdata *pdata = dramc->pdata; + unsigned int shu_level, pll_sel, offset; + unsigned int sdmpcw, posdiv, clkdiv, fbksel, sopen,
async_ca,ser_mode;drivers/memory/mediatek/Kconfig new file +4
-0+ unsigned int prediv_freq, posdiv_freq, vco_freq; + unsigned int final_rate; + + shu_level = read_reg_field(dramc->ddrphy_base, pdata-Quoted 6 lines
Quoted 4 lines
Quoted 1 line
regs[DRAMC_DPHY_DVFS_STA],
+ pdata-
Quoted 1 line
masks[DRAMC_DPHY_DVFS_SHU_LV]);
Don't creat your own wrappers. Use existing
FIELD_PREPstuff.Since the mask is not a constant, using
FIELD_GETwill result in a compilation error. Can I keep using 'read_reg_field' in the next version?Quoted 75 lines
Quoted 75 lines
+
pll_sel= read_reg_field(dramc->ddrphy_base, pdata-Quoted 1 line
regs[DRAMC_DPHY_DVFS_STA],
+ pdata-
Quoted 1 line
masks[DRAMC_DPHY_DVFS_PLL_SEL]);
drivers/memory/mediatek/Kconfig new file +5
-0+ offset = pdata->shuffle_offset * shu_level; + + sdmpcw = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL2]:
+ pdata-Quoted 1 line
regs[DRAMC_APHY_SHU_CLRPLL2])
+ offset,
+ pdata-Quoted 1 line
masks[DRAMC_APHY_PLL2_SDMPCW]);
drivers/memory/mediatek/Kconfig new file +3
-0+ posdiv = read_reg_field(dramc->anaphy_base, + ((pll_sel == 0) ? + pdata->regs[DRAMC_APHY_SHU_PHYPLL3]:
+ pdata-Quoted 1 line
regs[DRAMC_APHY_SHU_CLRPLL3])
+ offset,
+ pdata-Quoted 1 line
masks[DRAMC_APHY_PLL3_POSDIV]);
+ fbksel = read_reg_field(dramc->anaphy_base, pdata-
Quoted 1 line
regs[DRAMC_APHY_SHU_PHYPLL4] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_PLL4_FBKSEL]);
+ sopen = read_reg_field(dramc->anaphy_base, pdata-
Quoted 1 line
regs[DRAMC_APHY_ARPI0] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_ARPI0_SOPEN]);
+
async_ca= read_reg_field(dramc->anaphy_base, pdata-Quoted 1 line
regs[DRAMC_APHY_CA_ARDLL1] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_ARDLL1_CK_EN]);
+
ser_mode= read_reg_field(dramc->anaphy_base, pdata-Quoted 1 line
regs[DRAMC_APHY_B0_TX0] + offset,
+ pdata-
Quoted 1 line
masks[DRAMC_APHY_B0_TX0_SER_MODE]);
drivers/memory/mediatek/Kconfig new file +5
-0+ + clkdiv = (ser_mode == 1) ? 1 : 0; + posdiv &= ~(pdata->posdiv_purify); + + prediv_freq = pdata->ref_freq_mhz * (sdmpcw >> pdata-Quoted 1 line
prediv);
drivers/memory/mediatek/Kconfig new file +12
-0+ posdiv_freq = (prediv_freq >> posdiv) >> 1; + vco_freq = posdiv_freq << fbksel; + final_rate = vco_freq >> clkdiv; + + if (sopen == 1 && async_ca == 1) + final_rate >>= 1; + + return final_rate; +} + +/** + * mtk_dramc_get_data_rate - Calculate the current DRAM datarate
+ * @dev: Device pointer
+ *
+ * Return: DRAM Data Rate in Mbps or negative number for errorQuoted 8 lines
drivers/memory/mediatek/Kconfig
Quoted 6 lines
+ */
drivers/memory/mediatek/Kconfig new file +5
-0+static unsigned int mtk_dramc_get_data_rate(struct device *dev) +{ + struct mtk_dramc *dramc = dev_get_drvdata(dev); + + if (dramc->pdata->fmeter_version == 1)Drop, it's not possible to have other case.
Thank you for your suggestion.
In the future, other SoCs might use different fmeter version to calculate the DDR data rate. If we remove thefmeter_versionnow, future SoCs that cannot sharemtk_fmeter_v1will still need to add thefmeter_versionvariable.
Therefore, can I keep the current implementation for now.Quoted 14 lines
Quoted 11 lines
drivers/memory/mediatek/Kconfig new file +3
-0+ return mtk_fmeter_v1(dramc); + + dev_err(dev, "Frequency meter version %u not supported\n",
dramc->pdata->fmeter_version);drivers/memory/mediatek/Kconfig new file +5
-0+ return -EINVAL; +} + +static ssize_t dram_data_rate_show(struct device *dev, + struct device_attribute *attr,char *buf)
No ABI doc.
Quoted 7 lines
Why existing interconnect interface is not suitable here? This should
be an interconnect, otherwise what is the point of this driver? What
do
you exactly configure here?This driver specifically focuses on displaying the current DDR data rate, which is used for the DVFS (Dynamic Voltage and Frequency Scaling) feature to verify that DDR frequency adjustments are correctly
executed.
I will add the ABI documentation for thedram_data_rateattribute as follows, is this ok?What:
/sys/devices/platform/soc/XXXXXXXX.memory-
controller/dram_data_rate
Date: April 2025
KernelVersion: 6.14
Contact: Crystal Guo <[email protected]>
Description:
Reports the current DRAM data rate in Mbps.
Quoted 2 lines
Access: Read
Hi Krzysztof,
Sorry to bother you, may I proceed with the next version based on the content of my previous response regarding your suggestions?
Thanks
Crystal
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
drivers/memory/mediatek/Kconfig new file +25
-0+{ + return snprintf(buf, PAGE_SIZE, "DRAM data rate = %u\n", + mtk_dramc_get_data_rate(dev)); +} + +static DEVICE_ATTR_RO(dram_data_rate); + +static struct attribute *mtk_dramc_attrs[] = { + &dev_attr_dram_data_rate.attr, + NULL +}; +ATTRIBUTE_GROUPS(mtk_dramc); + +static const struct mtk_dramc_pdata dramc_pdata_mt8196 = { + .fmeter_version = 1, + .ref_freq_mhz = 26, + .regs = mtk_dramc_regs_mt8196, + .masks = mtk_dramc_masks_mt8196, + .posdiv_purify = BIT(2), + .prediv = 7, + .shuffle_offset = 0x700, +}; + +static const struct of_device_id mtk_dramc_of_ids[] = { + { .compatible = "mediatek,mt8196-dramc", .data =
&dramc_pdata_mt8196},drivers/memory/mediatek/Kconfig new file +17
-1+ { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mtk_dramc_of_ids); + +static struct platform_driver mtk_dramc_driver = { + .probe = mtk_dramc_probe, + .driver = { + .name = "mtk-dramc", + .of_match_table = mtk_dramc_of_ids, + .dev_groups = mtk_dramc_groups, + }, +}; +module_platform_driver(mtk_dramc_driver); + +MODULE_AUTHOR("Crystal Guo <[email protected]>"); +MODULE_DESCRIPTION("MediaTek DRAM Controller Driver"); +MODULE_LICENSE("GPL"); --2.18.0