Add SOCFPGA System Manager
Subsystems (9)
v2 cover Add SOCFPGA System Manager
From: Thor Thayer <[email protected]>
Add MFD driver for SOCFPGA System Manager to handle System Manager calls differently for ARM32 vs ARM64. The SOCFPGA System Manager includes registers from several SOC peripherals.
On ARM32, syscon handles this aggregated register grouping. Implement System Manager calls as regmap_mmio similar to syscon for ARM32 SOCFPGA systems.
The ARM64 System Manager can only be accessed from priority level EL3 so this new MFD driver handles the calls to EL3.
Thor Thayer (6):
mfd: altera-sysmgr: Add SOCFPGA System Manager
Documentation: dt: socfpga: Add S10 System Manager binding
ARM: socfpga_defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
arm64: defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
net: stmmac: socfpga: Use shared System Manager driver
arm64: dts: stratix10: New System Manager compatible
.../bindings/arm/altera/socfpga-system.txt | 12 + MAINTAINERS | 6 + arch/arm/configs/socfpga_defconfig | 1 + arch/arm64/boot/dts/altera/socfpga_stratix10.dtsi | 2 +- arch/arm64/configs/defconfig | 1 + drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/altera-sysmgr.c | 263 +++++++++++++++++++++ .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 4 +- include/linux/mfd/altera-sysmgr.h | 113 +++++++++ 10 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 drivers/mfd/altera-sysmgr.c create mode 100644 include/linux/mfd/altera-sysmgr.h
Signature · 1 line
2.7.4
PATCH v2 1/6 mfd: altera-sysmgr: Add SOCFPGA System Manager
From: Thor Thayer <[email protected]>
The SOCFPGA System Manager register block aggregates different peripheral functions into one area.
On 32 bit ARM parts, handle in the same way as syscon. On 64 bit ARM parts, the System Manager can only be accessed by EL3 secure mode. Since a SMC call to EL3 is required, this new driver uses regmaps similar to syscon to handle the SMC call.
Since regmaps abstract out the underlying register access, the changes to drivers accessing the System Manager are minimal.
---
v2 Implement Arnd's changes.
1. Change socfpga_is_s10() to check compatible string. Add new compatible string for Stratix10 in bindings and add proper detection method.
2. Replace base cast with resource_size_t member.
3. Change s10_sysmgr_regmap_cfg to altr_sysmgr_regmap_cfg to be generic.
4. Always use 4 byte width.
5. Initialize the .reg_read and .reg_write in S10 case only.
6. Remove call to syscon in 32bit ARM case and handle both ARM32 and ARM64 in of_sysmgr_register().
7. Replace IS_ERR_OR_NULL() with IS_ERR().
8. Remove compatible check functions except phandle function.
--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 10 ++ drivers/mfd/Makefile | 1 + drivers/mfd/altera-sysmgr.c | 263 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/altera-sysmgr.h | 113 ++++++++++++++++ 5 files changed, 393 insertions(+) create mode 100644 drivers/mfd/altera-sysmgr.c create mode 100644 include/linux/mfd/altera-sysmgr.h
MAINTAINERS +6 -0
@@ -707,6 +707,12 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-altera.c +ALTERA SYSTEM MANAGER DRIVER +M: Thor Thayer <[email protected]> +S: Maintained +F: drivers/mfd/altera-sysmgr.c +F: include/linux/mfd/altera-sysgmr.h + ALTERA SYSTEM RESOURCE DRIVER FOR ARRIA10 DEVKIT M: Thor Thayer <[email protected]> S: Maintained
drivers/mfd/Kconfig +10 -0
@@ -29,6 +29,16 @@ config MFD_ALTERA_A10SR accessing the external gpio extender (LEDs & buttons) and power supply alarms (hwmon). +config MFD_ALTERA_SYSMGR + bool "Altera SOCFPGA System Manager" + depends on (ARCH_SOCFPGA || ARCH_STRATIX10) && OF + select MFD_SYSCON + help + Select this to get System Manager support for all Altera branded + SOCFPGAs. The SOCFPGA System Manager handles all SOCFPGAs by + using regmap_mmio accesses for ARM32 parts and SMC calls to + EL3 for ARM64 parts. + config MFD_ACT8945A tristate "Active-semi ACT8945A" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -233,6 +233,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI) += intel_soc_pmic_chtdc_ti.o obj-$(CONFIG_MFD_MT6397) += mt6397-core.o obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o +obj-$(CONFIG_MFD_ALTERA_SYSMGR) += altera-sysmgr.o obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o obj-$(CONFIG_MFD_STM32_LPTIMER) += stm32-lptimer.o
drivers/mfd/altera-sysmgr.c new file +263 -0
263 lines not on this page · raw message
include/linux/mfd/altera-sysmgr.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCHv2 1/6] mfd: altera-sysmgr: Add SOCFPGA System Manager
Quoted 14 lines · On Fri, Dec 21, 2018 at 1:21 AM <[email protected]> wrote:
From: Thor Thayer <[email protected]>
The SOCFPGA System Manager register block aggregates different peripheral functions into one area.
On 32 bit ARM parts, handle in the same way as syscon. On 64 bit ARM parts, the System Manager can only be accessed by EL3 secure mode. Since a SMC call to EL3 is required, this new driver uses regmaps similar to syscon to handle the SMC call.Since regmaps abstract out the underlying register access, the changes to drivers accessing the System Manager are minimal.
Signed-off-by Thor Thayer <[email protected]>
Quoted 14 lines
---
v2 Implement Arnd's changes.
1. Changesocfpga_is_s10()to check compatible string. Add new compatible string for Stratix10 in bindings and add proper detection method.
2. Replace base cast withresource_size_tmember.
3. Changes10_sysmgr_regmap_cfgtoaltr_sysmgr_regmap_cfgto be generic.
4. Always use 4 byte width.
5. Initialize the .reg_read and .reg_write in S10 case only.
6. Remove call to syscon in 32bit ARM case and handle both ARM32 and ARM64 inof_sysmgr_register().
7. ReplaceIS_ERR_OR_NULL()withIS_ERR().
8. Remove compatible check functions except phandle function.
These all look good, thanks for the good updates!
Quoted 42 lines
drivers/mfd/altera-sysmgr.c new file +42
-0+struct regmap *altr_sysmgr_node_to_regmap (struct device_node *np) +{ +struct altr_sysmgr *sysmgr =NULL ; + +if (!p_sysmgr) + sysmgr =of_sysmgr_register (np); +else + sysmgr = p_sysmgr; + +if (IS_ERR (sysmgr)) +return ERR_CAST (sysmgr); + +return sysmgr->regmap; +} +EXPORT_SYMBOL_GPL (altr_sysmgr_node_to_regmap); + +struct regmap *altr_sysmgr_regmap_lookup_by_phandle (struct device_node *np, +const char *property) +{ +struct device_node *sysmgr_np; +struct regmap *regmap; + +if (property) + sysmgr_np =of_parse_phandle (np, property,0 ); +else + sysmgr_np = np; + +if (!sysmgr_np) +return ERR_PTR (-ENODEV ); + + regmap =altr_sysmgr_node_to_regmap (sysmgr_np); +of_node_put (sysmgr_np); + +return regmap; +} +EXPORT_SYMBOL_GPL (altr_sysmgr_regmap_lookup_by_phandle); + +static int sysmgr_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct altr_sysmgr *sysmgr; +struct resource *res;
drivers/mfd/altera-sysmgr.c line 224
Quoted 10 lines
drivers/mfd/altera-sysmgr.c new file +10
-0+ +/* Skip Initialization if already created */ +if (p_sysmgr) + goto finish; + + sysmgr =of_sysmgr_register (pdev->dev.of_node); +if (IS_ERR (sysmgr)) { +dev_err (dev,"regmap init failed\n" ); +return -ENODEV ; + }
It seems odd to still have these two ways of registering the sysmgr, from either the probe function or the lookup.
Since the sysmgr should always get probed before its users, you could try to change it like this:
- let only the probe() function register it and create the regmap, then set the regmap as the private data of the device.
- In lookup_by_phandle(), use driver_find_device() to look up the 'struct device' based on its of_node(), by comparing dev->of_node to of_parse_phandle(np, property).
- return the private data of the device.
That will also let you remove the global variable and make it (theoretically) work with multiple sysmgr devices, which is generally the preferred way to write a driver.
include/linux/mfd/altera-sysmgr.h line 22
Quoted 7 lines
include/linux/mfd/altera-sysmgr.h new file +7
-0+#ifdef CONFIG_MFD_ALTERA_SYSMGR +struct regmap *altr_sysmgr_node_to_regmap (struct device_node *np); +struct regmap *altr_sysmgr_regmap_lookup_by_compatible (const char *s); +struct regmap *altr_sysmgr_regmap_lookup_by_pdevname (const char *s); +struct regmap *altr_sysmgr_regmap_lookup_by_phandle (struct device_node *np, +const char *property); +
You seem to have some dead declarations from before the cleanup that should be removed now. Please go through the header file one more time to see what is actually still used.
Arnd
PATCH v2 2/6 Documentation: dt: socfpga: Add S10 System Manager binding
In reply to [email protected]From: Thor Thayer <[email protected]>
Add the device tree bindings for the Stratix10 System Manager.
---
v2 New compatible string and usage for Stratix10
--- .../devicetree/bindings/arm/altera/socfpga-system.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/arm/altera/socfpga-system.txt +12 -0
@@ -11,3 +11,15 @@ Example: reg = <0xffd08000 0x1000>; cpu1-start-addr = <0xffd080c4>; }; + +ARM64 - Stratix10 +Required properties: +- compatible : "altr,sys-mgr-s10" +- reg : Should contain 1 register range(address and length) + for system manager register. + +Example: + sysmgr@ffd12000 { + compatible = "altr,sys-mgr-s10"; + reg = <0xffd12000 0x228>; + };
Signature · 1 line
2.7.4
Re: [PATCHv2 2/6] Documentation: dt: socfpga: Add S10 System Manager binding
Quoted 11 lines · On Thu, 20 Dec 2018 18:23:18 -0600, [email protected] wrote:
From: Thor Thayer <[email protected]>
Add the device tree bindings for the Stratix10 System Manager.
Signed-off-by Thor Thayer <[email protected]>---
v2 New compatible string and usage for Stratix10--- .../devicetree/bindings/arm/altera/socfpga-system.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+)
PATCH v2 3/6 ARM: socfpga_defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
In reply to [email protected]From: Thor Thayer <[email protected]>
Add System Manager driver by default for SOCFPGA ARM32 platforms.
---
v2 No change
--- arch/arm/configs/socfpga_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/configs/socfpga_defconfig +1 -0
@@ -109,6 +109,7 @@ CONFIG_SENSORS_LTC2978_REGULATOR=y CONFIG_WATCHDOG=y CONFIG_DW_WATCHDOG=y CONFIG_MFD_ALTERA_A10SR=y +CONFIG_MFD_ALTERA_SYSMGR=y CONFIG_MFD_STMPE=y CONFIG_REGULATOR=y CONFIG_REGULATOR_FIXED_VOLTAGE=y
Signature · 1 line
2.7.4
PATCH v2 4/6 arm64: defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
In reply to [email protected]From: Thor Thayer <[email protected]>
Enable the Stratix10 System Manager by default.
---
v2 No change
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -392,6 +392,7 @@ CONFIG_MESON_WATCHDOG=m CONFIG_RENESAS_WDT=y CONFIG_UNIPHIER_WATCHDOG=y CONFIG_BCM2835_WDT=y +CONFIG_MFD_ALTERA_SYSMGR=y CONFIG_MFD_BD9571MWV=y CONFIG_MFD_AXP20X_RSB=y CONFIG_MFD_CROS_EC=y
Signature · 1 line
2.7.4
PATCH v2 5/6 net: stmmac: socfpga: Use shared System Manager driver
In reply to [email protected]From: Thor Thayer <[email protected]>
The ARM64 System Manager requires a different method of reading the System Manager than ARM32. A new System Manager driver was created to steer ARM32 System Manager calls to regmap_mmio and ARM64 System Manager calls to the new access method.
Convert from syscon to the shared System Manager driver so that both ARM64 and ARM32 are supported.
---
v2 No change to code. Update commit message.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +3 -1
@@ -15,6 +15,7 @@* Adopted from dwmac-sti.c */ +#include <linux/mfd/altera-sysmgr.h> #include <linux/mfd/syscon.h> #include <linux/of.h> #include <linux/of_address.h>
@@ -114,7 +115,8 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device * dwmac->interface =of_get_phy_mode (np); - sys_mgr_base_addr =syscon_regmap_lookup_by_phandle (np,"altr,sysmgr-syscon" ); + sys_mgr_base_addr = +altr_sysmgr_regmap_lookup_by_phandle (np,"altr,sysmgr-syscon" );if (IS_ERR (sys_mgr_base_addr)) {dev_info (dev,"No sysmgr-syscon node found\n" );return PTR_ERR (sys_mgr_base_addr);
Signature · 1 line
2.7.4
PATCH v2 6/6 arm64: dts: stratix10: New System Manager compatible
In reply to [email protected]From: Thor Thayer <[email protected]>
Use the new compatible string defined for the Stratix10 System Manager. Remove syscon since it is not correct on this platform.
---
v2 New. Use new Stratix10 System Manager compatible
--- arch/arm64/boot/dts/altera/socfpga_stratix10.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/altera/socfpga_stratix10.dtsi +1 -1
@@ -340,7 +340,7 @@ }; sysmgr: sysmgr@ffd12000 { - compatible = "altr,sys-mgr", "syscon"; + compatible = "altr,sys-mgr-s10"; reg = <0xffd12000 0x228>; };
Signature · 1 line
2.7.4