Add SOCFPGA System Manager
Subsystems (8)
cover Add SOCFPGA System Manager
From: Thor Thayer <[email protected]>
Add MFD driver for ARM64 SOCFPGA System Manager to steer System Manager calls appropriately.
The SOCFPGA System Manager includes registers from several SOC peripherals.
On ARM32, syscon handles this aggregated register grouping. Redirect System Manager calls 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 (4):
mfd: altera-sysmgr: Add SOCFPGA System Manager abstraction
ARM: socfpga_defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
arm64: defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
net: stmmac: socfpga: Convert to shared System Manager driver
MAINTAINERS | 6 + arch/arm/configs/socfpga_defconfig | 1 + arch/arm64/configs/defconfig | 1 + drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 1 + drivers/mfd/altera-sysmgr.c | 311 +++++++++++++++++++++ .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 4 +- include/linux/mfd/altera-sysmgr.h | 113 ++++++++ 8 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 drivers/mfd/altera-sysmgr.c create mode 100644 include/linux/mfd/altera-sysmgr.h
Signature · 1 line
2.7.4
PATCH RESEND 1/4 mfd: altera-sysmgr: Add SOCFPGA System Manager abstraction
From: Thor Thayer <[email protected]>
The SOCFPGA System Manager register block aggregate different peripheral functions into one place.
On 32 bit ARM parts, the syscon framework fits this problem well. On 64 bit ARM parts, the System Manager can only be accessed by EL3 secure mode. Since a SMC call to EL3 is required, a new driver using regmaps similar to syscon was created that handles the SMC call.
Since regmaps abstract out the underlying register access, the changes to drivers using System Manager are minimal.
---
Resend - update use_single_rw to use_single_read and
use_single_write which was added in 4.20.
--- MAINTAINERS | 6 + drivers/mfd/Kconfig | 9 ++ drivers/mfd/Makefile | 1 + drivers/mfd/altera-sysmgr.c | 311 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/altera-sysmgr.h | 113 ++++++++++++++ 5 files changed, 440 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 +9 -0
@@ -29,6 +29,15 @@ 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 syscon 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 +311 -0
311 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: [RESEND 1/4] mfd: altera-sysmgr: Add SOCFPGA System Manager abstraction
Quoted 13 lines · On Tue, Nov 13, 2018 at 5:03 PM <[email protected]> wrote:
From: Thor Thayer <[email protected]>
The SOCFPGA System Manager register block aggregate different peripheral functions into one place.
On 32 bit ARM parts, the syscon framework fits this problem well. On 64 bit ARM parts, the System Manager can only be accessed by EL3 secure mode. Since a SMC call to EL3 is required, a new driver using regmaps similar to syscon was created that handles the SMC call.
Since regmaps abstract out the underlying register access, the changes to drivers using System Manager are minimal.
Quoted 4 lines
Signed-off-by Thor Thayer <[email protected]>---
Resend - updateuse_single_rwtouse_single_readand
use_single_writewhich was added in 4.20.
Sorry for stepping in late here, I forgot to review it earlier and Lee had to remind me to take a look.
drivers/mfd/altera-sysmgr.c line 97
Quoted 11 lines
drivers/mfd/altera-sysmgr.c new file +11
-0+static const struct regmap_config s10_sysmgr_regmap_cfg = { + .name ="s10_sysmgr" , + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .reg_read = s10_protected_reg_read, + .reg_write = s10_protected_reg_write, + .fast_io = true, + .use_single_read = true, + .use_single_write = true, +};
The new regmap seems fine to me, that looks like a good way of abstracting the two hardware methods.
drivers/mfd/altera-sysmgr.c line 107
Quoted 9 lines
drivers/mfd/altera-sysmgr.c new file +9
-0+/** +* socfpga_is_s10 +* Determine if running on Stratix10 platform. +* Return: True if running Stratix10, otherwise false. +*/ +static int socfpga_is_s10 (void ) +{ +return of_machine_is_compatible ("altr,socfpga-stratix10" ); +}
I don't really like the way you are checking for a specific here here though, that is something that should only be done in an absolute emergency when there is no way of fixing the device tree files.
Since this is a new driver for a device that is not used in mainline kernels yet (AFAICT), let's fix the binding and add a proper detection method here.
Quoted 20 lines
drivers/mfd/altera-sysmgr.c new file +20
-0+ +/** +* of_sysmgr_register +* Create and register the Altera System Manager regmap. +* Return: Pointer to new sysmgr on success. +* Pointer error on failure. +*/ +static struct altr_sysmgr *of_sysmgr_register (struct device_node *np) +{ +struct altr_sysmgr *sysmgr; +struct regmap *regmap; +u32 reg_io_width; +int ret; +struct regmap_config sysmgr_config = s10_sysmgr_regmap_cfg; +struct resource res; + +if (!of_device_is_compatible (np,"altr,sys-mgr" )) +return ERR_PTR (-EINVAL ); + + sysmgr =kzalloc (sizeof (*sysmgr),GFP_KERNEL );
drivers/mfd/altera-sysmgr.c line 137
Quoted 10 lines
drivers/mfd/altera-sysmgr.c new file +10
-0+if (!sysmgr) +return ERR_PTR (-ENOMEM ); + +if (of_address_to_resource (np,0 , &res)) { + ret = -ENOMEM ; + goto err_map; + } + +/* Need physical address for SMCC call */ + sysmgr->base = (void __iomem *)res.start;
The cast here seems really ugly. Instead of mixinx up address spaces, how about adding a resource_size_t member in the sysmgr structure?
drivers/mfd/altera-sysmgr.c line 146
Quoted 7 lines
drivers/mfd/altera-sysmgr.c new file +7
-0+* search for reg-io-width property in DT. If it is not provided, +* default to 4 bytes. regmap_init will return an error if values +* are invalid so there is no need to check them here. +*/ + ret =of_property_read_u32 (np,"reg-io-width" , ®_io_width); +if (ret) + reg_io_width =4 ;
How likely is it that this would ever not be four bytes? It looks like you just copied this from syscon, but it really should not be needed.
drivers/mfd/altera-sysmgr.c line 175
Quoted 6 lines
drivers/mfd/altera-sysmgr.c new file +6
-0+struct regmap *altr_sysmgr_node_to_regmap (struct device_node *np) +{ +struct altr_sysmgr *sysmgr =NULL ; + +if (!socfpga_is_s10 ()) +return syscon_node_to_regmap (np);
Why do you go through syscon here? Doesn't this add a lot of complexity?
I'd suggest using regmap_init_mmio() directly and open-coding the initialization you need as you do for the s10 case.
drivers/mfd/altera-sysmgr.c line 183
Quoted 7 lines
drivers/mfd/altera-sysmgr.c new file +7
-0+if (!p_sysmgr) + sysmgr =of_sysmgr_register (np); +else + sysmgr = p_sysmgr; + +if (IS_ERR_OR_NULL (sysmgr)) +return ERR_CAST (sysmgr);
Don't use IS_ERR_OR_NULL(), it's just a sign that your API is bad. Instead, define the interface either so that you always return NULL on error or that you always return an PTR_ERR() value on error.
Quoted 8 lines
drivers/mfd/altera-sysmgr.c new file +8
-0+struct regmap *altr_sysmgr_regmap_lookup_by_compatible (const char *s) +{ +struct device_node *sysmgr_np; +struct regmap *regmap; + +if (!socfpga_is_s10 ()) +return syscon_regmap_lookup_by_compatible (s); +
drivers/mfd/altera-sysmgr.c line 206
Quoted 10 lines
drivers/mfd/altera-sysmgr.c new file +10
-0+ sysmgr_np =of_find_compatible_node (NULL ,NULL , s); +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_compatible);
That should not be needed, just look it up by phandle and be done with it. Again, lookup by compatible should only be needed for compatibility with old DTB files, but you should be able to fix the binding so you always have a phandle to the correct node here, at least for the s10 case.
For the older chips with existing DTs, I guess drivers can fall back to the syscon method directly.
Quoted 1 line
+EXPORT_SYMBOL_GPL(altr_sysmgr_regmap_lookup_by_pdevname);
Same comment.
Arnd
Re: [RESEND 1/4] mfd: altera-sysmgr: Add SOCFPGA System Manager abstraction
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Tue, Nov 13, 2018 at 5:03 PM <[email protected]> wrote:
From: Thor Thayer <[email protected]>
The SOCFPGA System Manager register block aggregate different peripheral functions into one place.
On 32 bit ARM parts, the syscon framework fits this problem well. On 64 bit ARM parts, the System Manager can only be accessed by EL3 secure mode. Since a SMC call to EL3 is required, a new driver using regmaps similar to syscon was created that handles the SMC call.
Since regmaps abstract out the underlying register access, the changes to drivers using System Manager are minimal.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Thor Thayer <[email protected]>---
Resend - updateuse_single_rwtouse_single_readand
use_single_writewhich was added in 4.20.Sorry for stepping in late here, I forgot to review it earlier and Lee had to remind me to take a look.
:) Thank you for the review and comments!
Quoted 30 lines
drivers/mfd/altera-sysmgr.c line 97
Quoted 11 lines
drivers/mfd/altera-sysmgr.c new file +11
-0+static const struct regmap_config s10_sysmgr_regmap_cfg = { + .name ="s10_sysmgr" , + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .reg_read = s10_protected_reg_read, + .reg_write = s10_protected_reg_write, + .fast_io = true, + .use_single_read = true, + .use_single_write = true, +};The new regmap seems fine to me, that looks like a good way of abstracting the two hardware methods.
drivers/mfd/altera-sysmgr.c line 107
Quoted 9 lines
drivers/mfd/altera-sysmgr.c new file +9
-0+/** +* socfpga_is_s10 +* Determine if running on Stratix10 platform. +* Return: True if running Stratix10, otherwise false. +*/ +static int socfpga_is_s10 (void ) +{ +return of_machine_is_compatible ("altr,socfpga-stratix10" ); +}I don't really like the way you are checking for a specific here here though, that is something that should only be done in an absolute emergency when there is no way of fixing the device tree files.
Quoted 4 lines
Since this is a new driver for a device that is not used in mainline kernels yet (AFAICT), let's fix the binding and add a proper detection method here.
Thank you. I'm not completely clear on this. Are you saying this function should test for a new compatible that is assigned to Stratix10 in the binding ("altr,sys-mgr-s10") instead of the machine name?
Quoted 26 lines
Quoted 26 lines
drivers/mfd/altera-sysmgr.c new file +26
-0+ +/** +* of_sysmgr_register +* Create and register the Altera System Manager regmap. +* Return: Pointer to new sysmgr on success. +* Pointer error on failure. +*/ +static struct altr_sysmgr *of_sysmgr_register (struct device_node *np) +{ +struct altr_sysmgr *sysmgr; +struct regmap *regmap; +u32 reg_io_width; +int ret; +struct regmap_config sysmgr_config = s10_sysmgr_regmap_cfg; +struct resource res; + +if (!of_device_is_compatible (np,"altr,sys-mgr" )) +return ERR_PTR (-EINVAL ); + + sysmgr =kzalloc (sizeof (*sysmgr),GFP_KERNEL ); +if (!sysmgr) +return ERR_PTR (-ENOMEM ); + +if (of_address_to_resource (np,0 , &res)) { + ret = -ENOMEM ; + goto err_map;
Quoted 9 lines
drivers/mfd/altera-sysmgr.c line 137
Quoted 4 lines
drivers/mfd/altera-sysmgr.c new file +4
-0+ } + +/* Need physical address for SMCC call */ + sysmgr->base = (void __iomem *)res.start;The cast here seems really ugly. Instead of mixinx up address spaces, how about adding a
resource_size_tmember in the sysmgr structure?
Yes. I will change.
Quoted 8 lines
drivers/mfd/altera-sysmgr.c line 146
Quoted 7 lines
drivers/mfd/altera-sysmgr.c new file +7
-0+* search for reg-io-width property in DT. If it is not provided, +* default to 4 bytes. regmap_init will return an error if values +* are invalid so there is no need to check them here. +*/ + ret =of_property_read_u32 (np,"reg-io-width" , ®_io_width); +if (ret) + reg_io_width =4 ;
Quoted 4 lines
How likely is it that this would ever not be four bytes? It looks like you just copied this from syscon, but it really should not be needed.
Yes. I will change.
Quoted 9 lines
drivers/mfd/altera-sysmgr.c line 175
Quoted 6 lines
drivers/mfd/altera-sysmgr.c new file +6
-0+struct regmap *altr_sysmgr_node_to_regmap (struct device_node *np) +{ +struct altr_sysmgr *sysmgr =NULL ; + +if (!socfpga_is_s10 ()) +return syscon_node_to_regmap (np);Why do you go through syscon here? Doesn't this add a lot of complexity?
Quoted 3 lines
I'd suggest using
regmap_init_mmio()directly and open-coding the initialization you need as you do for the s10 case.
Yes. It is more complex but I was concerned about re-implementing large parts of syscon for the ARM32 case.
However, re-implementing it will simplify the driver and keep both ARM32 and ARM64 together. Thanks for the suggestion - I will change it.
Quoted 8 lines
drivers/mfd/altera-sysmgr.c line 183
Quoted 7 lines
drivers/mfd/altera-sysmgr.c new file +7
-0+if (!p_sysmgr) + sysmgr =of_sysmgr_register (np); +else + sysmgr = p_sysmgr; + +if (IS_ERR_OR_NULL (sysmgr)) +return ERR_CAST (sysmgr);
Quoted 5 lines
Don't use
IS_ERR_OR_NULL(), it's just a sign that your API is bad. Instead, define the interface either so that you always return NULL on error or that you always return anPTR_ERR()value on error.
OK. I will change this.
Quoted 25 lines
Quoted 8 lines
drivers/mfd/altera-sysmgr.c new file +8
-0+struct regmap *altr_sysmgr_regmap_lookup_by_compatible (const char *s) +{ +struct device_node *sysmgr_np; +struct regmap *regmap; + +if (!socfpga_is_s10 ()) +return syscon_regmap_lookup_by_compatible (s); +drivers/mfd/altera-sysmgr.c line 206
Quoted 10 lines
drivers/mfd/altera-sysmgr.c new file +10
-0+ sysmgr_np =of_find_compatible_node (NULL ,NULL , s); +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_compatible);That should not be needed, just look it up by phandle and be done with it. Again, lookup by compatible should only be needed for compatibility with old DTB files, but you should be able to fix the binding so you always have a phandle to the correct node here, at least for the s10 case.
Quoted 9 lines
For the older chips with existing DTs, I guess drivers can fall back to the syscon method directly.
Quoted 1 line
+EXPORT_SYMBOL_GPL(altr_sysmgr_regmap_lookup_by_pdevname);
Same comment.
Arnd
Yes. I will make these changes.
Thanks so much for the review!
Re: [RESEND 1/4] mfd: altera-sysmgr: Add SOCFPGA System Manager abstraction
Quoted 18 lines · Thor Thayer
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
drivers/mfd/altera-sysmgr.c line 107
Quoted 7 lines · On Tue, Nov 13, 2018 at 5:03 PM <[email protected]> wrote:
From: Thor Thayer <[email protected]>
drivers/mfd/altera-sysmgr.c new file +4
-0+static int socfpga_is_s10 (void ) +{ +return of_machine_is_compatible ("altr,socfpga-stratix10" ); +}I don't really like the way you are checking for a specific here here though, that is something that should only be done in an absolute emergency when there is no way of fixing the device tree files.
Quoted 7 lines
Quoted 4 lines
Since this is a new driver for a device that is not used in mainline kernels yet (AFAICT), let's fix the binding and add a proper detection method here.
Thank you. I'm not completely clear on this. Are you saying this function should test for a new compatible that is assigned to Stratix10 in the binding ("altr,sys-mgr-s10") instead of the machine name?
Yes, exactly.
Arnd
PATCH RESEND 2/4 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.
--- 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 RESEND 3/4 arm64: defconfig: Enable CONFIG_MTD_ALTERA_SYSMGR
In reply to [email protected]From: Thor Thayer <[email protected]>
Enable the Stratix10 System Manager by default.
--- 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 RESEND 4/4 net: stmmac: socfpga: Convert to 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 syscon 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.
--- 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