Add Broadcom STB memory controller driver
v3 cover Add Broadcom STB memory controller driver
Hi Krzysztof,
This small patch series adds basic support for controlling self-refresh power down on Broadcom STB memory controllers. We might be able to contribute more features to the memory controller driver in the future like accurate reporting of the memory type, timings, and possibly some performance counters.
Changes in v3:
- made 'frequency' property optional to avoid introducing warnings for existing BMIPS and BCM7445 DTS files
- updated sysfs document to use a shorter and universal path
Changes in v2:
- merged the v1 first two patches
- added a sysfs document describing attributes exposed
- addressed feedback from Krzysztof regarding style and API usage
Florian Fainelli (3):
dt-bindings: memory-controller: Document Broadcom STB MEMC
Documentation: sysfs: Document Broadcom STB memc sysfs knobs
memory: Add Broadcom STB memory controller driver
.../ABI/testing/sysfs-platform-brcmstb-memc | 15 + .../bindings/arm/bcm/brcm,brcmstb.txt | 11 +- .../brcm,brcmstb-memc-ddr.yaml | 52 +++ drivers/memory/Kconfig | 9 + drivers/memory/Makefile | 1 + drivers/memory/brcmstb_memc.c | 302 ++++++++++++++++++ 6 files changed, 381 insertions(+), 9 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-brcmstb-memc create mode 100644 Documentation/devicetree/bindings/memory-controllers/brcm,brcmstb-memc-ddr.yaml create mode 100644 drivers/memory/brcmstb_memc.c
Signature · 1 line
2.25.1
PATCH v3 1/3 dt-bindings: memory-controller: Document Broadcom STB MEMC
Document the Broadcom STB memory controller which is a trivial binding for now with a set of compatible strings and single register.
Since we introduce this binding, the section in Documentation/devicetree/bindings/arm/bcm/brcm,brcmstb.txt is removed and this binding is referenced instead.
--- .../bindings/arm/bcm/brcm,brcmstb.txt | 11 +--- .../brcm,brcmstb-memc-ddr.yaml | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/memory-controllers/brcm,brcmstb-memc-ddr.yaml
Documentation/devicetree/bindings/arm/bcm/brcm,brcmstb.txt +2 -9
@@ -187,15 +187,8 @@ Required properties: Sequencer DRAM parameters and control registers. Used for Self-Refresh Power-Down (SRPD), among other things. -Required properties: -- compatible : should contain one of these - "brcm,brcmstb-memc-ddr-rev-b.2.1" - "brcm,brcmstb-memc-ddr-rev-b.2.2" - "brcm,brcmstb-memc-ddr-rev-b.2.3" - "brcm,brcmstb-memc-ddr-rev-b.3.0" - "brcm,brcmstb-memc-ddr-rev-b.3.1" - "brcm,brcmstb-memc-ddr" -- reg : the MEMC DDR register range +See Documentation/devicetree/bindings/memory-controllers/brcm,memc.yaml for a +full list of supported compatible strings and properties. Example:
Documentation/devicetree/bindings/memory-controllers/brcm,brcmstb-memc-ddr.yaml new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 2/3 Documentation: sysfs: Document Broadcom STB memc sysfs knobs
In reply to Florian FainelliDocument the "srpd" and "frequency" sysfs attributes exposed by the brcmstb_memc driver.
--- .../ABI/testing/sysfs-platform-brcmstb-memc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-brcmstb-memc
Documentation/ABI/testing/sysfs-platform-brcmstb-memc new file +15 -0
@@ -0,0 +1,15 @@ +What: /sys/bus/platform/devices/*/srpd +Date: July 2022 +KernelVersion: 5.21 +Contact: Florian Fainelli <[email protected]> +Description: + Self Refresh Power Down (SRPD) inactivity timeout counted in + internal DDR controller clock cycles. Possible values range + from 0 (disable inactivity timeout) to 65535 (0xffff). + +What: /sys/bus/platform/devices/*/frequency +Date: July 2022 +KernelVersion: 5.21 +Contact: Florian Fainelli <[email protected]> +Description: + DDR PHY frequency in Hz.
Signature · 1 line
2.25.1
PATCH v3 3/3 memory: Add Broadcom STB memory controller driver
In reply to Florian FainelliAdd support for configuring the Self Refresh Power Down (SRPD) inactivity timeout on Broadcom STB chips. This is used to conserve power when the DRAM activity is reduced.
--- drivers/memory/Kconfig | 9 + drivers/memory/Makefile | 1 + drivers/memory/brcmstb_memc.c | 302 ++++++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+) create mode 100644 drivers/memory/brcmstb_memc.c
drivers/memory/Kconfig +9 -0
@@ -66,6 +66,15 @@ config BRCMSTB_DPFE for the DRAM's temperature. Slower refresh rate means cooler RAM, higher refresh rate means hotter RAM. +config BRCMSTB_MEMC + tristate "Broadcom STB MEMC driver" + default ARCH_BRCMSTB + depends on ARCH_BRCMSTB || COMPILE_TEST + help + This driver provides a way to configure the Broadcom STB memory + controller and specifically control the Self Refresh Power Down + (SRPD) inactivity timeout. + config BT1_L2_CTL bool "Baikal-T1 CM2 L2-RAM Cache Control Block" depends on MIPS_BAIKAL_T1 || COMPILE_TEST
drivers/memory/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_ARM_PL172_MPMC) += pl172.o obj-$(CONFIG_ATMEL_SDRAMC) += atmel-sdramc.o obj-$(CONFIG_ATMEL_EBI) += atmel-ebi.o obj-$(CONFIG_BRCMSTB_DPFE) += brcmstb_dpfe.o +obj-$(CONFIG_BRCMSTB_MEMC) += brcmstb_memc.o obj-$(CONFIG_BT1_L2_CTL) += bt1-l2-ctl.o obj-$(CONFIG_TI_AEMIF) += ti-aemif.o obj-$(CONFIG_TI_EMIF) += emif.o
drivers/memory/brcmstb_memc.c new file +302 -0
302 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 15 lines · Florian Fainelli
Add support for configuring the Self Refresh Power Down (SRPD) inactivity timeout on Broadcom STB chips. This is used to conserve power when the DRAM activity is reduced.
drivers/memory/brcmstb_memc.c new file +9
-0+static int __maybe_unused brcmstb_memc_resume (struct device *dev) +{ +struct brcmstb_memc *memc =dev_get_drvdata (dev); + +if (memc->timeout_cycles ==0 ) +return 0 ; + +return brcmstb_memc_srpd_config (memc, memc->timeout_cycles); +}
drivers/memory/brcmstb_memc.c line 293
Quoted 10 lines
drivers/memory/brcmstb_memc.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(brcmstb_memc_pm_ops, brcmstb_memc_suspend, + brcmstb_memc_resume); + +static struct platform_driver brcmstb_memc_driver = { + .probe = brcmstb_memc_probe, + .remove = brcmstb_memc_remove, + .driver = { + .name ="brcmstb_memc" , + .owner =THIS_MODULE ,
No need, run coccinelle.
drivers/memory/brcmstb_memc.c line 295
Quoted 2 lines
drivers/memory/brcmstb_memc.c new file +2
-0+ .of_match_table = brcmstb_memc_of_match, + .pm = &brcmstb_memc_pm_ops,
Shouldn't this be pm_ptr()? and then no need for __maybe_unused in brcmstb_memc_resume/suspend.
drivers/memory/brcmstb_memc.c line 302
Quoted 7 lines
drivers/memory/brcmstb_memc.c new file +7
-0+ }, +}; +module_platform_driver (brcmstb_memc_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Broadcom" ); +MODULE_DESCRIPTION ("DDR SRPD driver for Broadcom STB chips" );
Best regards,
Krzysztof
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 29 lines · Krzysztof Kozlowski
Quoted 15 lines · Florian Fainelli
Add support for configuring the Self Refresh Power Down (SRPD) inactivity timeout on Broadcom STB chips. This is used to conserve power when the DRAM activity is reduced.
drivers/memory/brcmstb_memc.c new file +9
-0+static int __maybe_unused brcmstb_memc_resume (struct device *dev) +{ +struct brcmstb_memc *memc =dev_get_drvdata (dev); + +if (memc->timeout_cycles ==0 ) +return 0 ; + +return brcmstb_memc_srpd_config (memc, memc->timeout_cycles); +}drivers/memory/brcmstb_memc.c line 293
Quoted 10 lines
drivers/memory/brcmstb_memc.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(brcmstb_memc_pm_ops, brcmstb_memc_suspend, + brcmstb_memc_resume); + +static struct platform_driver brcmstb_memc_driver = { + .probe = brcmstb_memc_probe, + .remove = brcmstb_memc_remove, + .driver = { + .name ="brcmstb_memc" , + .owner =THIS_MODULE ,No need, run coccinelle.
Quoted 5 lines
drivers/memory/brcmstb_memc.c line 295
Quoted 2 lines
drivers/memory/brcmstb_memc.c new file +2
-0+ .of_match_table = brcmstb_memc_of_match, + .pm = &brcmstb_memc_pm_ops,Shouldn't this be
pm_ptr()? and then no need for__maybe_unusedin brcmstb_memc_resume/suspend.
How can one can remove __maybe_unused without causing a warning for the CONFIG_PM=n case, not that I needed to build to convince myself, but still did anyway:
drivers/memory/brcmstb_memc.c:275:12: warning: 'brcmstb_memc_resume' defined but not used [-Wunused-function]
static int brcmstb_memc_resume(struct device *dev)
^~~~~~~~~~~~~~~~~~~
drivers/memory/brcmstb_memc.c:252:12: warning: 'brcmstb_memc_suspend' defined but not used [-Wunused-function]
static int brcmstb_memc_suspend(struct device *dev)
^~~~~~~~~~~~~~~~~~~~unless you also implied enclosing those functions under an #if IS_ENABLED(CONFIG_PM) or something which is IMHO less preferable.
Signature · 1 line
Florian
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 43 lines · Florian Fainelli
Quoted 29 lines · Krzysztof Kozlowski
Quoted 15 lines · Florian Fainelli
Add support for configuring the Self Refresh Power Down (SRPD) inactivity timeout on Broadcom STB chips. This is used to conserve power when the DRAM activity is reduced.
drivers/memory/brcmstb_memc.c new file +9
-0+static int __maybe_unused brcmstb_memc_resume (struct device *dev) +{ +struct brcmstb_memc *memc =dev_get_drvdata (dev); + +if (memc->timeout_cycles ==0 ) +return 0 ; + +return brcmstb_memc_srpd_config (memc, memc->timeout_cycles); +}drivers/memory/brcmstb_memc.c line 293
Quoted 10 lines
drivers/memory/brcmstb_memc.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(brcmstb_memc_pm_ops, brcmstb_memc_suspend, + brcmstb_memc_resume); + +static struct platform_driver brcmstb_memc_driver = { + .probe = brcmstb_memc_probe, + .remove = brcmstb_memc_remove, + .driver = { + .name ="brcmstb_memc" , + .owner =THIS_MODULE ,No need, run coccinelle.
Quoted 5 lines
drivers/memory/brcmstb_memc.c line 295
Quoted 2 lines
drivers/memory/brcmstb_memc.c new file +2
-0+ .of_match_table = brcmstb_memc_of_match, + .pm = &brcmstb_memc_pm_ops,Shouldn't this be
pm_ptr()? and then no need for__maybe_unusedin brcmstb_memc_resume/suspend.How can one can remove
__maybe_unusedwithout causing a warning for theCONFIG_PM=ncase, not that I needed to build to convince myself, but still did anyway:
drivers/memory/brcmstb_memc.c:275:12: warning: 'brcmstb_memc_resume' defined but not used [-Wunused-function]
static intbrcmstb_memc_resume(struct device *dev)
Quoted 8 lines
^~~~~~~~~~~~~~~~~~~ drivers/memory/brcmstb_memc.c:252:12: warning: 'brcmstb_memc_suspend' defined but not used [-Wunused-function] static int brcmstb_memc_suspend(struct device *dev) ^~~~~~~~~~~~~~~~~~~~unless you also implied enclosing those functions under an #if
IS_ENABLED(CONFIG_PM)or something which is IMHO less preferable.
Are you sure you added also pm_ptr()? I don't see such warnings with W=1 and final object does not have the functions (for a different driver but same principle).
Best regards,
Krzysztof
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 50 lines · Krzysztof Kozlowski
Quoted 49 lines · Florian Fainelli
Quoted 29 lines · Krzysztof Kozlowski
Quoted 15 lines · Florian Fainelli
Add support for configuring the Self Refresh Power Down (SRPD) inactivity timeout on Broadcom STB chips. This is used to conserve power when the DRAM activity is reduced.
drivers/memory/brcmstb_memc.c new file +9
-0+static int __maybe_unused brcmstb_memc_resume (struct device *dev) +{ +struct brcmstb_memc *memc =dev_get_drvdata (dev); + +if (memc->timeout_cycles ==0 ) +return 0 ; + +return brcmstb_memc_srpd_config (memc, memc->timeout_cycles); +}drivers/memory/brcmstb_memc.c line 293
Quoted 10 lines
drivers/memory/brcmstb_memc.c new file +10
-0+ +static SIMPLE_DEV_PM_OPS(brcmstb_memc_pm_ops, brcmstb_memc_suspend, + brcmstb_memc_resume); + +static struct platform_driver brcmstb_memc_driver = { + .probe = brcmstb_memc_probe, + .remove = brcmstb_memc_remove, + .driver = { + .name ="brcmstb_memc" , + .owner =THIS_MODULE ,No need, run coccinelle.
Quoted 5 lines
drivers/memory/brcmstb_memc.c line 295
Quoted 2 lines
drivers/memory/brcmstb_memc.c new file +2
-0+ .of_match_table = brcmstb_memc_of_match, + .pm = &brcmstb_memc_pm_ops,Shouldn't this be
pm_ptr()? and then no need for__maybe_unusedin brcmstb_memc_resume/suspend.How can one can remove
__maybe_unusedwithout causing a warning for theCONFIG_PM=ncase, not that I needed to build to convince myself, but still did anyway:
drivers/memory/brcmstb_memc.c:275:12: warning: 'brcmstb_memc_resume' defined but not used [-Wunused-function]
static intbrcmstb_memc_resume(struct device *dev)^~~~~~~~~~~~~~~~~~~ drivers/memory/brcmstb_memc.c:252:12: warning: 'brcmstb_memc_suspend' defined but not used [-Wunused-function] static int brcmstb_memc_suspend(struct device *dev) ^~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 2 lines
unless you also implied enclosing those functions under an #if
IS_ENABLED(CONFIG_PM)or something which is IMHO less preferable.Are you sure you added also
pm_ptr()? I don't see such warnings with W=1 and final object does not have the functions (for a different driver but same principle).
Yes I am sure I added pm_ptr() see the v4 I just submitted. I don't see how the compiler cannot warn about the functions being unused the day they stop being referenced by the pm_ops structure which is eliminated?
Signature · 1 line
Florian
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 10 lines · Florian Fainelli
Quoted 6 lines
Quoted 2 lines
unless you also implied enclosing those functions under an #if
IS_ENABLED(CONFIG_PM)or something which is IMHO less preferable.Are you sure you added also
pm_ptr()? I don't see such warnings with W=1 and final object does not have the functions (for a different driver but same principle).Yes I am sure I added
pm_ptr()see the v4 I just submitted. I don't see how the compiler cannot warn about the functions being unused the day they stop being referenced by thepm_opsstructure which is eliminated?
I don't have the answer how it exactly works (or which gcc version introduced it), but I tested it and the functions were not present in the object file, thus of course no warnings.
The driver change I am referring to is:
https://lore.kernel.org/all/[email protected]/
I think the only difference against your v4 is:DEFINE_SIMPLE_DEV_PM_OPS
and lack of __maybe_unused on the functions.
The DEFINE_SIMPLE_DEV_PM_OPS itself adds __maybe_unused for !CONFIG_PM case, but I don't think it is relevant.
Best regards,
Krzysztof
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 20 lines · Krzysztof Kozlowski
Quoted 10 lines · Florian Fainelli
Quoted 6 lines
Quoted 2 lines
unless you also implied enclosing those functions under an #if
IS_ENABLED(CONFIG_PM)or something which is IMHO less preferable.Are you sure you added also
pm_ptr()? I don't see such warnings with W=1 and final object does not have the functions (for a different driver but same principle).Yes I am sure I added
pm_ptr()see the v4 I just submitted. I don't see how the compiler cannot warn about the functions being unused the day they stop being referenced by thepm_opsstructure which is eliminated?I don't have the answer how it exactly works (or which gcc version introduced it), but I tested it and the functions were not present in the object file, thus of course no warnings.
The driver change I am referring to is:
https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
I think the only difference against your v4 is:
DEFINE_SIMPLE_DEV_PM_OPS
and lack of__maybe_unusedon the functions.The
DEFINE_SIMPLE_DEV_PM_OPSitself adds__maybe_unusedfor !CONFIG_PM case, but I don't think it is relevant.
It definitively is relevant here. SIMPLE_DEV_PM_OPS without __maybe_unused results in the following pre-processed code:
static int brcmstb_memc_suspend(struct device *dev) {
struct brcmstb_memc *memc = dev_get_drvdata(dev); void *cfg = memc->ddr_ctrl + memc->srpd_offset; u32 val;
if (memc->timeout_cycles == 0)
return 0;
val = ({ u32 __r = (( __u32)(__le32)(( __le32) __raw_readl(cfg)));__r; });
val &= ~((((1UL))) << (16));
__raw_writel(( u32) (( __le32)(__u32)(val)),cfg);
(void)({ u32 __r = (( __u32)(__le32)(( __le32) __raw_readl(cfg)));__r; });
return 0;
}
static int brcmstb_memc_resume(struct device *dev) {
struct brcmstb_memc *memc = dev_get_drvdata(dev);
if (memc->timeout_cycles == 0)
return 0;
return brcmstb_memc_srpd_config(memc, memc->timeout_cycles);
}
static const struct dev_pm_ops __attribute__((__unused__)) brcmstb_memc_pm_ops = { }
;
static struct platform_driver brcmstb_memc_driver = {
.probe = brcmstb_memc_probe,
.remove = brcmstb_memc_remove,
.driver = {
.name = "brcmstb_memc",
.of_match_table = brcmstb_memc_of_match,
.pm = ((1) ? ((&brcmstb_memc_pm_ops)) : ((void *)0)),
},
};
Now with DEFINE_SIMPLE_PM_OPS, we get the following instead:
static const struct dev_pm_ops brcmstb_memc_pm_ops = { .suspend = ((0) ? ((brcmstb_memc_suspend)) : ((void *)0)), .resume = ((0) ? ((brcmstb_memc_resume)) : ((void *)0)), .freeze = ((0) ? ((brcmstb_memc_suspend)) : ((void *)0)), .thaw = ((0) ? ((brcmstb_memc_resume)) : ((void *)0)), .poweroff = ((0) ? ((brcmstb_memc_suspend)) : ((void *)0)), .restore = ((0) ? ((brcmstb_memc_resume)) : ((void *)0)), .runtime_suspend = ((void *)0), .runtime_resume = ((void *)0), .runtime_idle = ((void *)0), }
;
static struct platform_driver brcmstb_memc_driver = {
.probe = brcmstb_memc_probe,
.remove = brcmstb_memc_remove,
.driver = {
.name = "brcmstb_memc",
.of_match_table = brcmstb_memc_of_match,
.pm = ((1) ? ((&brcmstb_memc_pm_ops)) : ((void *)0)),
},
};
so we will continue to reference the functions, but eventually we will eliminate those at the optimization stage by figuring out that this is dead code, therefore it can be eliminated. Note that in both cases the object does not contain brcmstb_memc_{resume,suspend} which makes sense because the warnings are generated at the time the code is processed, and the dead code elimination at one of the optimization stages.
I can spin a v5 with DEFINE_SIMPLE_PM_OPS if you prefer to get rid of the __maybe_unused.
Signature · 1 line
Florian
Re: [PATCH v3 3/3] memory: Add Broadcom STB memory controller driver
Quoted 26 lines · Florian Fainelli
Quoted 24 lines · Krzysztof Kozlowski
Quoted 10 lines · Florian Fainelli
Quoted 6 lines
Quoted 2 lines
unless you also implied enclosing those functions under an #if
IS_ENABLED(CONFIG_PM)or something which is IMHO less preferable.Are you sure you added also
pm_ptr()? I don't see such warnings with W=1 and final object does not have the functions (for a different driver but same principle).Yes I am sure I added
pm_ptr()see the v4 I just submitted. I don't see how the compiler cannot warn about the functions being unused the day they stop being referenced by thepm_opsstructure which is eliminated?I don't have the answer how it exactly works (or which gcc version introduced it), but I tested it and the functions were not present in the object file, thus of course no warnings.
The driver change I am referring to is:
https://lore.kernel.org/all/[email protected]/I think the only difference against your v4 is:
DEFINE_SIMPLE_DEV_PM_OPS
and lack of__maybe_unusedon the functions.
Quoted 6 lines
Quoted 2 lines
The
DEFINE_SIMPLE_DEV_PM_OPSitself adds__maybe_unusedfor !CONFIG_PM case, but I don't think it is relevant.It definitively is relevant here.
SIMPLE_DEV_PM_OPSwithout__maybe_unusedresults in the following pre-processed code:
What I was referring to is "__maybe_unused" is not relevant here. The DEFINE_SIMPLE_DEV_PM_OPS (with pm_ptr()) are the change you need.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel