mbox series

[00/24] ARM: at91: pm: add support for sama7g5

Message ID 20210331105908.23027-1-claudiu.beznea@microchip.com
Headers show
Series ARM: at91: pm: add support for sama7g5 | expand

Message

Claudiu Beznea March 31, 2021, 10:58 a.m. UTC
Hi,

This series adds PM support for SAMA7G5. The standby, ulp0, ulp1, and
backup modes are supported.

Thank you,
Claudiu Beznea

Claudiu Beznea (23):
  ARM: at91: pm: move pm_bu to soc_pm data structure
  ARM: at91: pm: move the setup of soc_pm.bu->suspended
  ARM: at91: pm: document at91_soc_pm structure
  ARM: at91: pm: check for different controllers in at91_pm_modes_init()
  ARM: at91: pm: do not initialize pdev
  ARM: at91: pm: use r7 instead of tmp1
  ARM: at91: pm: avoid push and pop on stack while memory is in
    self-refersh
  ARM: at91: pm: s/CONFIG_SOC_SAM9X60/CONFIG_HAVE_AT91_SAM9X60_PLL/g
  ARM: at91: pm: add support for waiting MCK1..4
  ARM: at91: sfrbu: add sfrbu registers definitions for sama7g5
  ARM: at91: ddr: add registers definitions for sama7g5's ddr
  ARM: at91: pm: add self-refresh support for sama7g5
  ARM: at91: pm: add support for MCK1..4 save/restore for ulp modes
  ARM: at91: pm: add support for 2.5V LDO regulator control
  ARM: at91: pm: wait for ddr power mode off
  dt-bindings: atmel-sysreg: add bindings for sama7g5
  ARM: at91: pm: add sama7g5 ddr controller
  ARM: at91: pm: add sama7g5 ddr phy controller
  ARM: at91: pm: save ddr phy calibration data to securam
  ARM: at91: pm: add backup mode support for SAMA7G5
  ARM: at91: pm: add sama7g5's pmc
  ARM: at91: pm: add pm support for SAMA7G5
  ARM: at91: pm: add sama7g5 shdwc

Eugen Hristev (1):
  ARM: at91: sama7: introduce sama7 SoC family

 .../devicetree/bindings/arm/atmel-sysregs.txt |  15 +-
 arch/arm/mach-at91/Makefile                   |   1 +
 arch/arm/mach-at91/generic.h                  |   2 +
 arch/arm/mach-at91/pm.c                       | 343 ++++++--
 arch/arm/mach-at91/pm.h                       |   3 +
 arch/arm/mach-at91/pm_data-offsets.c          |   2 +
 arch/arm/mach-at91/pm_suspend.S               | 827 +++++++++++++-----
 arch/arm/mach-at91/sama7.c                    |  49 ++
 include/soc/at91/sama7-ddr.h                  |  80 ++
 include/soc/at91/sama7-sfrbu.h                |  34 +
 10 files changed, 1066 insertions(+), 290 deletions(-)
 create mode 100644 arch/arm/mach-at91/sama7.c
 create mode 100644 include/soc/at91/sama7-ddr.h
 create mode 100644 include/soc/at91/sama7-sfrbu.h

Comments

Alexandre Belloni March 31, 2021, 2:44 p.m. UTC | #1
On 31/03/2021 13:58:45+0300, Claudiu Beznea wrote:
> Move pm_bu to soc_pm data structure.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  arch/arm/mach-at91/pm.c | 34 +++++++++++++++++++++-------------
>  1 file changed, 21 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
> index 90dcdfe3b3d0..e13ceef7ac9a 100644
> --- a/arch/arm/mach-at91/pm.c
> +++ b/arch/arm/mach-at91/pm.c
> @@ -27,10 +27,25 @@
>  #include "generic.h"
>  #include "pm.h"
>  
> +/**
> + * struct at91_pm_bu - AT91 power management backup unit data structure
> + * @suspended: true if suspended to backup mode
> + * @reserved: reserved
> + * @canary: canary data for memory checking after exit from backup mode
> + * @resume: resume API
> + */
> +struct at91_pm_bu {
> +	int suspended;
> +	unsigned long reserved;
> +	phys_addr_t canary;
> +	phys_addr_t resume;
> +};
> +
>  struct at91_soc_pm {
>  	int (*config_shdwc_ws)(void __iomem *shdwc, u32 *mode, u32 *polarity);
>  	int (*config_pmc_ws)(void __iomem *pmc, u32 mode, u32 polarity);
>  	const struct of_device_id *ws_ids;
> +	struct at91_pm_bu *bu;
>  	struct at91_pm_data data;
>  };
>  
> @@ -71,13 +86,6 @@ static int at91_pm_valid_state(suspend_state_t state)
>  
>  static int canary = 0xA5A5A5A5;
>  
> -static struct at91_pm_bu {
> -	int suspended;
> -	unsigned long reserved;
> -	phys_addr_t canary;
> -	phys_addr_t resume;
> -} *pm_bu;
> -
>  struct wakeup_source_info {
>  	unsigned int pmc_fsmr_bit;
>  	unsigned int shdwc_mr_bit;
> @@ -288,7 +296,7 @@ static int at91_suspend_finish(unsigned long val)
>  static void at91_pm_suspend(suspend_state_t state)
>  {
>  	if (soc_pm.data.mode == AT91_PM_BACKUP) {
> -		pm_bu->suspended = 1;
> +		soc_pm.bu->suspended = 1;
>  
>  		cpu_suspend(0, at91_suspend_finish);
>  
> @@ -657,16 +665,16 @@ static int __init at91_pm_backup_init(void)
>  		goto securam_fail;
>  	}
>  
> -	pm_bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu));
> -	if (!pm_bu) {
> +	soc_pm.bu = (void *)gen_pool_alloc(sram_pool, sizeof(struct at91_pm_bu));
> +	if (!soc_pm.bu) {
>  		pr_warn("%s: unable to alloc securam!\n", __func__);
>  		ret = -ENOMEM;
>  		goto securam_fail;
>  	}
>  
> -	pm_bu->suspended = 0;
> -	pm_bu->canary = __pa_symbol(&canary);
> -	pm_bu->resume = __pa_symbol(cpu_resume);
> +	soc_pm.bu->suspended = 0;
> +	soc_pm.bu->canary = __pa_symbol(&canary);
> +	soc_pm.bu->resume = __pa_symbol(cpu_resume);
>  
>  	return 0;
>  
> -- 
> 2.25.1
>
Alexandre Belloni March 31, 2021, 3:54 p.m. UTC | #2
On 31/03/2021 13:58:54+0300, Claudiu Beznea wrote:
> Add SFRBU registers definitions for SAMA7G5.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  include/soc/at91/sama7-sfrbu.h | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>  create mode 100644 include/soc/at91/sama7-sfrbu.h
> 
> diff --git a/include/soc/at91/sama7-sfrbu.h b/include/soc/at91/sama7-sfrbu.h
> new file mode 100644
> index 000000000000..76b740810d34
> --- /dev/null
> +++ b/include/soc/at91/sama7-sfrbu.h
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Microchip SAMA7 SFRBU registers offsets and bit definitions.
> + *
> + * Copyright (C) [2020] Microchip Technology Inc. and its subsidiaries
> + *
> + * Author: Claudu Beznea <claudiu.beznea@microchip.com>
> + */
> +
> +#ifndef __SAMA7_SFRBU_H__
> +#define __SAMA7_SFRBU_H__
> +
> +#ifdef CONFIG_SOC_SAMA7
> +
> +#define AT91_SFRBU_PSWBU			(0x00)		/* SFRBU Power Switch BU Control Register */
> +#define		AT91_SFRBU_PSWBU_PSWKEY		(0x4BD20C << 8)	/* Specific value mandatory to allow writing of other register bits */
> +#define		AT91_SFRBU_PSWBU_STATE		(1 << 2)	/* Power switch BU state */
> +#define		AT91_SFRBU_PSWBU_SOFTSWITCH	(1 << 1)	/* Power switch BU source selection */
> +#define		AT91_SFRBU_PSWBU_CTRL		(1 << 0)	/* Power switch BU control */

Please use BIT

> +
> +#define AT91_SFRBU_25LDOCR			(0x0C)		/* SFRBU 2.5V LDO Control Register */
> +#define		AT91_SFRBU_25LDOCR_LDOANAKEY	(0x3B6E18 << 8)	/* Specific value mandatory to allow writing of other register bits. */
> +#define		AT91_SFRBU_25LDOCR_STATE	(1 << 3)	/* LDOANA Switch On/Off Control */
> +#define		AT91_SFRBU_25LDOCR_LP		(1 << 2)	/* LDOANA Low-Power Mode Control */
> +#define		AT91_SFRBU_PD_VALUE_MSK		(0x3)

GENMASK

> +#define		AT91_SFRBU_25LDOCR_PD_VALUE(v)	((v) & AT91_SFRBU_PD_VALUE_MSK)	/* LDOANA Pull-down value */

this macro is not necessary, you can use FIELD_PREP with the previous
define.
Alexandre Belloni March 31, 2021, 4:01 p.m. UTC | #3
On 31/03/2021 13:59:06+0300, Claudiu Beznea wrote:
> From: Eugen Hristev <eugen.hristev@microchip.com>
> 
> Introduce new family of SoCs, sama7, and first SoC, sama7g5.
> 
> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>  arch/arm/mach-at91/Makefile |  1 +
>  arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
>  create mode 100644 arch/arm/mach-at91/sama7.c
> 
> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
> index f565490f1b70..6cc6624cddac 100644
> --- a/arch/arm/mach-at91/Makefile
> +++ b/arch/arm/mach-at91/Makefile
> @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)	+= at91sam9.o
>  obj-$(CONFIG_SOC_SAM9X60)	+= sam9x60.o
>  obj-$(CONFIG_SOC_SAMA5)		+= sama5.o
>  obj-$(CONFIG_SOC_SAMV7)		+= samv7.o
> +obj-$(CONFIG_SOC_SAMA7)		+= sama7.o
>  
>  # Power Management
>  obj-$(CONFIG_ATMEL_PM)		+= pm.o pm_suspend.o
> diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
> new file mode 100644
> index 000000000000..e04cadb569ad
> --- /dev/null
> +++ b/arch/arm/mach-at91/sama7.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Setup code for SAMA7
> + *
> + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
> + *
> + */
> +
> +#include <linux/of.h>
> +#include <linux/of_platform.h>
> +
> +#include <asm/mach/arch.h>
> +#include <asm/system_misc.h>
> +
> +#include "generic.h"
> +
> +static void __init sama7_common_init(void)
> +{
> +	of_platform_default_populate(NULL, NULL, NULL);

Is this necessary? This is left as a workaround for the old SoCs using
pinctrl-at91. I guess this will be using pio4 so this has to be removed.

> +}
> +
> +static void __init sama7_dt_device_init(void)
> +{
> +	sama7_common_init();
> +}
> +
> +static const char *const sama7_dt_board_compat[] __initconst = {
> +	"microchip,sama7",
> +	NULL
> +};
> +
> +DT_MACHINE_START(sama7_dt, "Microchip SAMA7")
> +	/* Maintainer: Microchip */
> +	.init_machine	= sama7_dt_device_init,
> +	.dt_compat	= sama7_dt_board_compat,
> +MACHINE_END
> +
> +static const char *const sama7g5_dt_board_compat[] __initconst = {
> +	"microchip,sama7g5",
> +	NULL
> +};
> +
> +DT_MACHINE_START(sama7g5_dt, "Microchip SAMA7G5")
> +	/* Maintainer: Microchip */
> +	.init_machine	= sama7_dt_device_init,
> +	.dt_compat	= sama7g5_dt_board_compat,
> +MACHINE_END
> +
> -- 
> 2.25.1
>
Claudiu Beznea April 1, 2021, 9:34 a.m. UTC | #4
On 31.03.2021 18:54, Alexandre Belloni wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 31/03/2021 13:58:54+0300, Claudiu Beznea wrote:
>> Add SFRBU registers definitions for SAMA7G5.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  include/soc/at91/sama7-sfrbu.h | 34 ++++++++++++++++++++++++++++++++++
>>  1 file changed, 34 insertions(+)
>>  create mode 100644 include/soc/at91/sama7-sfrbu.h
>>
>> diff --git a/include/soc/at91/sama7-sfrbu.h b/include/soc/at91/sama7-sfrbu.h
>> new file mode 100644
>> index 000000000000..76b740810d34
>> --- /dev/null
>> +++ b/include/soc/at91/sama7-sfrbu.h
>> @@ -0,0 +1,34 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Microchip SAMA7 SFRBU registers offsets and bit definitions.
>> + *
>> + * Copyright (C) [2020] Microchip Technology Inc. and its subsidiaries
>> + *
>> + * Author: Claudu Beznea <claudiu.beznea@microchip.com>
>> + */
>> +
>> +#ifndef __SAMA7_SFRBU_H__
>> +#define __SAMA7_SFRBU_H__
>> +
>> +#ifdef CONFIG_SOC_SAMA7
>> +
>> +#define AT91_SFRBU_PSWBU                     (0x00)          /* SFRBU Power Switch BU Control Register */
>> +#define              AT91_SFRBU_PSWBU_PSWKEY         (0x4BD20C << 8) /* Specific value mandatory to allow writing of other register bits */
>> +#define              AT91_SFRBU_PSWBU_STATE          (1 << 2)        /* Power switch BU state */
>> +#define              AT91_SFRBU_PSWBU_SOFTSWITCH     (1 << 1)        /* Power switch BU source selection */
>> +#define              AT91_SFRBU_PSWBU_CTRL           (1 << 0)        /* Power switch BU control */
> 
> Please use BIT
> 
>> +
>> +#define AT91_SFRBU_25LDOCR                   (0x0C)          /* SFRBU 2.5V LDO Control Register */
>> +#define              AT91_SFRBU_25LDOCR_LDOANAKEY    (0x3B6E18 << 8) /* Specific value mandatory to allow writing of other register bits. */
>> +#define              AT91_SFRBU_25LDOCR_STATE        (1 << 3)        /* LDOANA Switch On/Off Control */
>> +#define              AT91_SFRBU_25LDOCR_LP           (1 << 2)        /* LDOANA Low-Power Mode Control */
>> +#define              AT91_SFRBU_PD_VALUE_MSK         (0x3)
> 
> GENMASK
> 
>> +#define              AT91_SFRBU_25LDOCR_PD_VALUE(v)  ((v) & AT91_SFRBU_PD_VALUE_MSK) /* LDOANA Pull-down value */
> 
> this macro is not necessary, you can use FIELD_PREP with the previous
> define.
> 

This file (as well as include/soc/at91/sama7-ddr.h) is used in
arch/arm/mach-at91/pm_suspend.S who's content is executed from CPU internal
SRAM. I chose to have these defines w/o BIT(), GENMASK() and friends to not
depend on the bitops.h who's size might be changed at any time.

> 
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
Claudiu Beznea April 1, 2021, 9:38 a.m. UTC | #5
On 31.03.2021 19:01, Alexandre Belloni wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 31/03/2021 13:59:06+0300, Claudiu Beznea wrote:
>> From: Eugen Hristev <eugen.hristev@microchip.com>
>>
>> Introduce new family of SoCs, sama7, and first SoC, sama7g5.
>>
>> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  arch/arm/mach-at91/Makefile |  1 +
>>  arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
>>  2 files changed, 49 insertions(+)
>>  create mode 100644 arch/arm/mach-at91/sama7.c
>>
>> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
>> index f565490f1b70..6cc6624cddac 100644
>> --- a/arch/arm/mach-at91/Makefile
>> +++ b/arch/arm/mach-at91/Makefile
>> @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)    += at91sam9.o
>>  obj-$(CONFIG_SOC_SAM9X60)    += sam9x60.o
>>  obj-$(CONFIG_SOC_SAMA5)              += sama5.o
>>  obj-$(CONFIG_SOC_SAMV7)              += samv7.o
>> +obj-$(CONFIG_SOC_SAMA7)              += sama7.o
>>
>>  # Power Management
>>  obj-$(CONFIG_ATMEL_PM)               += pm.o pm_suspend.o
>> diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
>> new file mode 100644
>> index 000000000000..e04cadb569ad
>> --- /dev/null
>> +++ b/arch/arm/mach-at91/sama7.c
>> @@ -0,0 +1,48 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Setup code for SAMA7
>> + *
>> + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
>> + *
>> + */
>> +
>> +#include <linux/of.h>
>> +#include <linux/of_platform.h>
>> +
>> +#include <asm/mach/arch.h>
>> +#include <asm/system_misc.h>
>> +
>> +#include "generic.h"
>> +
>> +static void __init sama7_common_init(void)
>> +{
>> +     of_platform_default_populate(NULL, NULL, NULL);
> 
> Is this necessary? This is left as a workaround for the old SoCs using
> pinctrl-at91. I guess this will be using pio4 so this has to be removed.

OK, I'll have a look. BTW, SAMA5D2 which is also using PIO4 calls
of_platform_default_populate(NULL, NULL, NULL);

> 
>> +}
>> +
>> +static void __init sama7_dt_device_init(void)
>> +{
>> +     sama7_common_init();
>> +}
>> +
>> +static const char *const sama7_dt_board_compat[] __initconst = {
>> +     "microchip,sama7",
>> +     NULL
>> +};
>> +
>> +DT_MACHINE_START(sama7_dt, "Microchip SAMA7")
>> +     /* Maintainer: Microchip */
>> +     .init_machine   = sama7_dt_device_init,
>> +     .dt_compat      = sama7_dt_board_compat,
>> +MACHINE_END
>> +
>> +static const char *const sama7g5_dt_board_compat[] __initconst = {
>> +     "microchip,sama7g5",
>> +     NULL
>> +};
>> +
>> +DT_MACHINE_START(sama7g5_dt, "Microchip SAMA7G5")
>> +     /* Maintainer: Microchip */
>> +     .init_machine   = sama7_dt_device_init,
>> +     .dt_compat      = sama7g5_dt_board_compat,
>> +MACHINE_END
>> +
>> --
>> 2.25.1
>>
> 
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
Claudiu Beznea April 1, 2021, 10:24 a.m. UTC | #6
On 01.04.2021 12:38, Claudiu Beznea - M18063 wrote:
> On 31.03.2021 19:01, Alexandre Belloni wrote:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>>
>> On 31/03/2021 13:59:06+0300, Claudiu Beznea wrote:
>>> From: Eugen Hristev <eugen.hristev@microchip.com>
>>>
>>> Introduce new family of SoCs, sama7, and first SoC, sama7g5.
>>>
>>> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
>>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>>> ---
>>>  arch/arm/mach-at91/Makefile |  1 +
>>>  arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
>>>  2 files changed, 49 insertions(+)
>>>  create mode 100644 arch/arm/mach-at91/sama7.c
>>>
>>> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
>>> index f565490f1b70..6cc6624cddac 100644
>>> --- a/arch/arm/mach-at91/Makefile
>>> +++ b/arch/arm/mach-at91/Makefile
>>> @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)    += at91sam9.o
>>>  obj-$(CONFIG_SOC_SAM9X60)    += sam9x60.o
>>>  obj-$(CONFIG_SOC_SAMA5)              += sama5.o
>>>  obj-$(CONFIG_SOC_SAMV7)              += samv7.o
>>> +obj-$(CONFIG_SOC_SAMA7)              += sama7.o
>>>
>>>  # Power Management
>>>  obj-$(CONFIG_ATMEL_PM)               += pm.o pm_suspend.o
>>> diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
>>> new file mode 100644
>>> index 000000000000..e04cadb569ad
>>> --- /dev/null
>>> +++ b/arch/arm/mach-at91/sama7.c
>>> @@ -0,0 +1,48 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/*
>>> + * Setup code for SAMA7
>>> + *
>>> + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
>>> + *
>>> + */
>>> +
>>> +#include <linux/of.h>
>>> +#include <linux/of_platform.h>
>>> +
>>> +#include <asm/mach/arch.h>
>>> +#include <asm/system_misc.h>
>>> +
>>> +#include "generic.h"
>>> +
>>> +static void __init sama7_common_init(void)
>>> +{
>>> +     of_platform_default_populate(NULL, NULL, NULL);
>>
>> Is this necessary? This is left as a workaround for the old SoCs using
>> pinctrl-at91. I guess this will be using pio4 so this has to be removed.
> 
> OK, I'll have a look. BTW, SAMA5D2 which is also using PIO4 calls
> of_platform_default_populate(NULL, NULL, NULL);

Without this call the PM code (arch/arm/mach-at/pm.c) is not able to locate
proper DT nodes:

[    0.194615] at91_pm_backup_init: failed to find securam device!
[    0.201393] at91_pm_sram_init: failed to find sram device!
[    0.207449] AT91: PM not supported, due to no SRAM allocated

> 
>>
>>> +}
>>> +
>>> +static void __init sama7_dt_device_init(void)
>>> +{
>>> +     sama7_common_init();
>>> +}
>>> +
>>> +static const char *const sama7_dt_board_compat[] __initconst = {
>>> +     "microchip,sama7",
>>> +     NULL
>>> +};
>>> +
>>> +DT_MACHINE_START(sama7_dt, "Microchip SAMA7")
>>> +     /* Maintainer: Microchip */
>>> +     .init_machine   = sama7_dt_device_init,
>>> +     .dt_compat      = sama7_dt_board_compat,
>>> +MACHINE_END
>>> +
>>> +static const char *const sama7g5_dt_board_compat[] __initconst = {
>>> +     "microchip,sama7g5",
>>> +     NULL
>>> +};
>>> +
>>> +DT_MACHINE_START(sama7g5_dt, "Microchip SAMA7G5")
>>> +     /* Maintainer: Microchip */
>>> +     .init_machine   = sama7_dt_device_init,
>>> +     .dt_compat      = sama7g5_dt_board_compat,
>>> +MACHINE_END
>>> +
>>> --
>>> 2.25.1
>>>
>>
>> --
>> Alexandre Belloni, co-owner and COO, Bootlin
>> Embedded Linux and Kernel engineering
>> https://bootlin.com
>>
>
Nicolas Ferre April 8, 2021, 3:24 p.m. UTC | #7
On 01/04/2021 at 12:24, Claudiu Beznea - M18063 wrote:
> On 01.04.2021 12:38, Claudiu Beznea - M18063 wrote:
>> On 31.03.2021 19:01, Alexandre Belloni wrote:
>>> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>>>
>>> On 31/03/2021 13:59:06+0300, Claudiu Beznea wrote:
>>>> From: Eugen Hristev <eugen.hristev@microchip.com>
>>>>
>>>> Introduce new family of SoCs, sama7, and first SoC, sama7g5.
>>>>
>>>> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
>>>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>>>> ---
>>>>   arch/arm/mach-at91/Makefile |  1 +
>>>>   arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
>>>>   2 files changed, 49 insertions(+)
>>>>   create mode 100644 arch/arm/mach-at91/sama7.c
>>>>
>>>> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
>>>> index f565490f1b70..6cc6624cddac 100644
>>>> --- a/arch/arm/mach-at91/Makefile
>>>> +++ b/arch/arm/mach-at91/Makefile
>>>> @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)    += at91sam9.o
>>>>   obj-$(CONFIG_SOC_SAM9X60)    += sam9x60.o
>>>>   obj-$(CONFIG_SOC_SAMA5)              += sama5.o
>>>>   obj-$(CONFIG_SOC_SAMV7)              += samv7.o
>>>> +obj-$(CONFIG_SOC_SAMA7)              += sama7.o
>>>>
>>>>   # Power Management
>>>>   obj-$(CONFIG_ATMEL_PM)               += pm.o pm_suspend.o
>>>> diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
>>>> new file mode 100644
>>>> index 000000000000..e04cadb569ad
>>>> --- /dev/null
>>>> +++ b/arch/arm/mach-at91/sama7.c
>>>> @@ -0,0 +1,48 @@
>>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>>> +/*
>>>> + * Setup code for SAMA7
>>>> + *
>>>> + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
>>>> + *
>>>> + */
>>>> +
>>>> +#include <linux/of.h>
>>>> +#include <linux/of_platform.h>
>>>> +
>>>> +#include <asm/mach/arch.h>
>>>> +#include <asm/system_misc.h>
>>>> +
>>>> +#include "generic.h"
>>>> +
>>>> +static void __init sama7_common_init(void)
>>>> +{
>>>> +     of_platform_default_populate(NULL, NULL, NULL);
>>>
>>> Is this necessary? This is left as a workaround for the old SoCs using
>>> pinctrl-at91. I guess this will be using pio4 so this has to be removed.
>>
>> OK, I'll have a look. BTW, SAMA5D2 which is also using PIO4 calls
>> of_platform_default_populate(NULL, NULL, NULL);
> 
> Without this call the PM code (arch/arm/mach-at/pm.c) is not able to locate
> proper DT nodes:
> 
> [    0.194615] at91_pm_backup_init: failed to find securam device!
> [    0.201393] at91_pm_sram_init: failed to find sram device!
> [    0.207449] AT91: PM not supported, due to no SRAM allocated

Okay, so we can't afford removing these calls to sama5d2 and upcoming 
sama7g5 right now.

Is it a common pattern to have to reach DT content in the early stages 
that explicit call to of_platform_default_populate() tries to solve?

Best regards,
   Nicolas


>>>> +}
>>>> +
>>>> +static void __init sama7_dt_device_init(void)
>>>> +{
>>>> +     sama7_common_init();
>>>> +}
>>>> +
>>>> +static const char *const sama7_dt_board_compat[] __initconst = {
>>>> +     "microchip,sama7",
>>>> +     NULL
>>>> +};
>>>> +
>>>> +DT_MACHINE_START(sama7_dt, "Microchip SAMA7")
>>>> +     /* Maintainer: Microchip */
>>>> +     .init_machine   = sama7_dt_device_init,
>>>> +     .dt_compat      = sama7_dt_board_compat,
>>>> +MACHINE_END
>>>> +
>>>> +static const char *const sama7g5_dt_board_compat[] __initconst = {
>>>> +     "microchip,sama7g5",
>>>> +     NULL
>>>> +};
>>>> +
>>>> +DT_MACHINE_START(sama7g5_dt, "Microchip SAMA7G5")
>>>> +     /* Maintainer: Microchip */
>>>> +     .init_machine   = sama7_dt_device_init,
>>>> +     .dt_compat      = sama7g5_dt_board_compat,
>>>> +MACHINE_END
>>>> +
>>>> --
>>>> 2.25.1
>>>>
>>>
>>> --
>>> Alexandre Belloni, co-owner and COO, Bootlin
>>> Embedded Linux and Kernel engineering
>>> https://bootlin.com
>>>
>>
>
Nicolas Ferre April 8, 2021, 3:30 p.m. UTC | #8
Hi,

On 31/03/2021 at 12:59, Claudiu Beznea wrote:
> From: Eugen Hristev <eugen.hristev@microchip.com>
> 
> Introduce new family of SoCs, sama7, and first SoC, sama7g5.
> 
> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
>   arch/arm/mach-at91/Makefile |  1 +
>   arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
>   2 files changed, 49 insertions(+)
>   create mode 100644 arch/arm/mach-at91/sama7.c
> 
> diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
> index f565490f1b70..6cc6624cddac 100644
> --- a/arch/arm/mach-at91/Makefile
> +++ b/arch/arm/mach-at91/Makefile
> @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)	+= at91sam9.o
>   obj-$(CONFIG_SOC_SAM9X60)	+= sam9x60.o
>   obj-$(CONFIG_SOC_SAMA5)		+= sama5.o
>   obj-$(CONFIG_SOC_SAMV7)		+= samv7.o
> +obj-$(CONFIG_SOC_SAMA7)		+= sama7.o

Nit: alphabetic order tells that it should be before samv7

>   
>   # Power Management
>   obj-$(CONFIG_ATMEL_PM)		+= pm.o pm_suspend.o
> diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
> new file mode 100644
> index 000000000000..e04cadb569ad
> --- /dev/null
> +++ b/arch/arm/mach-at91/sama7.c
> @@ -0,0 +1,48 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Setup code for SAMA7
> + *
> + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
> + *
> + */
> +
> +#include <linux/of.h>
> +#include <linux/of_platform.h>
> +
> +#include <asm/mach/arch.h>
> +#include <asm/system_misc.h>
> +
> +#include "generic.h"
> +
> +static void __init sama7_common_init(void)
> +{
> +	of_platform_default_populate(NULL, NULL, NULL);
> +}
> +
> +static void __init sama7_dt_device_init(void)
> +{
> +	sama7_common_init();
> +}
> +
> +static const char *const sama7_dt_board_compat[] __initconst = {
> +	"microchip,sama7",
> +	NULL
> +};
> +
> +DT_MACHINE_START(sama7_dt, "Microchip SAMA7")
> +	/* Maintainer: Microchip */
> +	.init_machine	= sama7_dt_device_init,
> +	.dt_compat	= sama7_dt_board_compat,
> +MACHINE_END
> +
> +static const char *const sama7g5_dt_board_compat[] __initconst = {
> +	"microchip,sama7g5",
> +	NULL
> +};
> +
> +DT_MACHINE_START(sama7g5_dt, "Microchip SAMA7G5")
> +	/* Maintainer: Microchip */
> +	.init_machine	= sama7_dt_device_init,
> +	.dt_compat	= sama7g5_dt_board_compat,
> +MACHINE_END

I'm not sure we need two DT_MACHINE_START() entries and associated 
functions right now. Probably the most generic one is sufficient.
We can add such distinction in the future if the need arises.

Regards,
   Nicolas
Alexandre Belloni April 8, 2021, 5:44 p.m. UTC | #9
On 08/04/2021 17:24:39+0200, Nicolas Ferre wrote:
> On 01/04/2021 at 12:24, Claudiu Beznea - M18063 wrote:
> > On 01.04.2021 12:38, Claudiu Beznea - M18063 wrote:
> > > On 31.03.2021 19:01, Alexandre Belloni wrote:
> > > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > > > 
> > > > On 31/03/2021 13:59:06+0300, Claudiu Beznea wrote:
> > > > > From: Eugen Hristev <eugen.hristev@microchip.com>
> > > > > 
> > > > > Introduce new family of SoCs, sama7, and first SoC, sama7g5.
> > > > > 
> > > > > Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
> > > > > Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> > > > > ---
> > > > >   arch/arm/mach-at91/Makefile |  1 +
> > > > >   arch/arm/mach-at91/sama7.c  | 48 +++++++++++++++++++++++++++++++++++++
> > > > >   2 files changed, 49 insertions(+)
> > > > >   create mode 100644 arch/arm/mach-at91/sama7.c
> > > > > 
> > > > > diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
> > > > > index f565490f1b70..6cc6624cddac 100644
> > > > > --- a/arch/arm/mach-at91/Makefile
> > > > > +++ b/arch/arm/mach-at91/Makefile
> > > > > @@ -9,6 +9,7 @@ obj-$(CONFIG_SOC_AT91SAM9)    += at91sam9.o
> > > > >   obj-$(CONFIG_SOC_SAM9X60)    += sam9x60.o
> > > > >   obj-$(CONFIG_SOC_SAMA5)              += sama5.o
> > > > >   obj-$(CONFIG_SOC_SAMV7)              += samv7.o
> > > > > +obj-$(CONFIG_SOC_SAMA7)              += sama7.o
> > > > > 
> > > > >   # Power Management
> > > > >   obj-$(CONFIG_ATMEL_PM)               += pm.o pm_suspend.o
> > > > > diff --git a/arch/arm/mach-at91/sama7.c b/arch/arm/mach-at91/sama7.c
> > > > > new file mode 100644
> > > > > index 000000000000..e04cadb569ad
> > > > > --- /dev/null
> > > > > +++ b/arch/arm/mach-at91/sama7.c
> > > > > @@ -0,0 +1,48 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > > > +/*
> > > > > + * Setup code for SAMA7
> > > > > + *
> > > > > + * Copyright (C) 2021 Microchip Technology, Inc. and its subsidiaries
> > > > > + *
> > > > > + */
> > > > > +
> > > > > +#include <linux/of.h>
> > > > > +#include <linux/of_platform.h>
> > > > > +
> > > > > +#include <asm/mach/arch.h>
> > > > > +#include <asm/system_misc.h>
> > > > > +
> > > > > +#include "generic.h"
> > > > > +
> > > > > +static void __init sama7_common_init(void)
> > > > > +{
> > > > > +     of_platform_default_populate(NULL, NULL, NULL);
> > > > 
> > > > Is this necessary? This is left as a workaround for the old SoCs using
> > > > pinctrl-at91. I guess this will be using pio4 so this has to be removed.
> > > 
> > > OK, I'll have a look. BTW, SAMA5D2 which is also using PIO4 calls
> > > of_platform_default_populate(NULL, NULL, NULL);
> > 
> > Without this call the PM code (arch/arm/mach-at/pm.c) is not able to locate
> > proper DT nodes:
> > 
> > [    0.194615] at91_pm_backup_init: failed to find securam device!
> > [    0.201393] at91_pm_sram_init: failed to find sram device!
> > [    0.207449] AT91: PM not supported, due to no SRAM allocated
> 
> Okay, so we can't afford removing these calls to sama5d2 and upcoming
> sama7g5 right now.
> 
> Is it a common pattern to have to reach DT content in the early stages that
> explicit call to of_platform_default_populate() tries to solve?
> 

That's fine, I didn't remember about that one, we can keep the call.