Skip to contentSkip to conversation

sunxi: rework pinctrl and add T113s support

RFC PATCH In review Andre Przywara 5 participants 62 messages Dec 6, 2022 – Jun 21, 2023

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

cover sunxi: rework pinctrl and add T113s support

Hi,

this is some early attempt at supporting the new SoC series that covers the Allwinner D1 siblings R528 and T113s. They all share the same die, although the D1 and D1s use RISC-V cores, which requires more plumbing, to use the sunxi code across two architectures. Getting the R528 support in should help a bit in sorting out what's new peripheral code and what is architecture dependent. IIUC, Samuel has that running, although with some hacks, the number of which this series tries to reduce.

The most interesting part of this is the pincontroller rework, this tackles two issues:
- For the first time in the history of mainline Allwinner support the pincontroller changed the register layout. The code here tries to abstract the differences away, so both variants can share the code peacefully.
- For the above mentioned reason, the pincontroller code is quite old, and is mostly spread out across arch/arm, in a pre-DM style, even though we have real DM support in U-Boot proper. We need the non-DM version for the (ARM-only?) legacy SPL, so can't get rid of that completely. This series also tries to modernise that code, and moves it into board/sunxi/, where it can be more easily shared with RISC-V.

The preliminary MangoPi MQ-R bits on top are mostly for illustration purposes, and in case someone wants to give it a try. For some probably stupid reason MMC doesn't work, although the driver loads fine. Also this omits the DRAM code, although there is some GPLed code out there, which can be lifted into here, with some extra work.

I would mostly appreciate to have some opinion on the pinctrl patches: I understand that patch 03/17 isn't strictly necessary, but I always disliked U-Boot's "use C structs to model MMIO register frames" approach, so thought now is the time to get rid of that ;-) Also I am unsure about patch 06/17, which seems like a step back (spreading per-SoC data over several files), but I actually aim at getting rid of cpu_sun[x]i.h altogether, since we should not really need it, except for some exceptions.
The third patch I would like to hear feedback about is patch 08/17. Finally patch 14/17 would deserve some extra pair of eyes.

Please let me know if you have any opinions!

Cheers,
Andre

P.S. I understand there is some code to support those SoCs out there, apologies if I just re-implemented some of it. Please point me to patches that seem upstream-worthy, and I will happily integrate them in here, potentially replacing some of my patches.

Andre Przywara (15):
sunxi: remove CONFIG_SATAPWR
sunxi: remove CONFIG_MACPWR
pinctrl: sunxi: remove struct sunxi_gpio
pinctrl: sunxi: add GPIO in/out wrappers
pinctrl: sunxi: move pinctrl code and remove GPIO_EXTRA_HEADER
pinctrl: sunxi: move PIO_BASE into sunxi_gpio.h
pinctrl: sunxi: add new D1 pinctrl support
sunxi: introduce NCAT2 generation model
pinctrl: sunxi: add Allwinner D1 pinctrl description
sunxi: clock: D1/R528: Enable PLL LDO during PLL1 setup
sunxi: clock: support D1/R528 PLL6 clock
sunxi: add early Allwinner R528/T113 SoC support
sunxi: refactor serial base addresses to avoid asm/arch/cpu.h
arm: sunxi: add Allwinner T113s devicetree stub
sunxi: add preliminary MangoPi MQ-R board support

Samuel Holland (2):
clk: sunxi: Add support for the D1 CCU
riscv: dts: allwinner: Add the D1/D1s SoC devicetree

 arch/arm/Kconfig                              |   3 +-
 arch/arm/cpu/armv7/sunxi/sram.c               |   1 +
 arch/arm/cpu/armv8/fel_utils.S                |   1 +
 arch/arm/dts/Makefile                         |   2 +
 arch/arm/dts/sun8i-t113s-mangopi-mq-r.dts     |  54 ++
 arch/arm/dts/sun8i-t113s.dtsi                 |  59 ++
 arch/arm/include/asm/arch-sunxi/clock.h       |   3 +-
 .../include/asm/arch-sunxi/clock_sun50i_h6.h  |   8 +
 arch/arm/include/asm/arch-sunxi/cpu.h         |   2 +
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h   |  17 -
 .../include/asm/arch-sunxi/cpu_sun50i_h6.h    |   7 -
 arch/arm/include/asm/arch-sunxi/cpu_sun9i.h   |   9 -
 .../include/asm/arch-sunxi/cpu_sunxi_ncat2.h  |  49 +
 arch/arm/include/asm/arch-sunxi/mmc.h         |   2 +-
 arch/arm/include/asm/arch-sunxi/prcm.h        |   2 +-
 arch/arm/include/asm/arch-sunxi/serial.h      |  32 +
 arch/arm/include/asm/arch-sunxi/timer.h       |   2 +-
 arch/arm/mach-sunxi/Kconfig                   |  51 +-
 arch/arm/mach-sunxi/Makefile                  |   2 +-
 arch/arm/mach-sunxi/board.c                   |   9 +-
 arch/arm/mach-sunxi/clock_sun50i_h6.c         |  38 +-
 arch/arm/mach-sunxi/cpu_info.c                |   2 +
 arch/arm/mach-sunxi/dram_suniv.c              |   2 +-
 arch/arm/mach-sunxi/gtbus_sun9i.c             |   1 +
 arch/arm/mach-sunxi/pinmux.c                  |  78 --
 arch/arm/mach-sunxi/spl_spi_sunxi.c           |   1 +
 arch/arm/mach-sunxi/timer.c                   |   1 +
 arch/riscv/dts/sun20i-d1.dtsi                 |  66 ++
 arch/riscv/dts/sun20i-d1s.dtsi                |  76 ++
 arch/riscv/dts/sunxi-d1-t113.dtsi             |  15 +
 arch/riscv/dts/sunxi-d1s-t113.dtsi            | 844 ++++++++++++++++++
 board/sunxi/Makefile                          |   2 +
 board/sunxi/board.c                           |  25 +-
 board/sunxi/chip.c                            |   2 +-
 board/sunxi/dram_sun8i_r528.c                 |   9 +
 board/sunxi/pinctrl.c                         |  94 ++
 common/spl/Kconfig                            |   2 +-
 configs/A10-OLinuXino-Lime_defconfig          |   1 -
 configs/A20-OLinuXino-Lime2-eMMC_defconfig    |   1 -
 configs/A20-OLinuXino-Lime2_defconfig         |   1 -
 configs/A20-OLinuXino-Lime_defconfig          |   1 -
 configs/A20-OLinuXino_MICRO-eMMC_defconfig    |   1 -
 configs/A20-OLinuXino_MICRO_defconfig         |   1 -
 configs/A20-Olimex-SOM-EVB_defconfig          |   1 -
 configs/A20-Olimex-SOM204-EVB-eMMC_defconfig  |   1 -
 configs/A20-Olimex-SOM204-EVB_defconfig       |   1 -
 configs/Bananapi_M2_Ultra_defconfig           |   1 -
 configs/Bananapi_defconfig                    |   1 -
 configs/Bananapro_defconfig                   |   1 -
 configs/Cubieboard2_defconfig                 |   1 -
 configs/Cubieboard_defconfig                  |   1 -
 configs/Cubietruck_defconfig                  |   1 -
 configs/Itead_Ibox_A20_defconfig              |   1 -
 configs/Lamobo_R1_defconfig                   |   2 -
 configs/Linksprite_pcDuino3_Nano_defconfig    |   1 -
 configs/Linksprite_pcDuino3_defconfig         |   1 -
 configs/Mele_A1000_defconfig                  |   1 -
 configs/Orangepi_defconfig                    |   1 -
 configs/Orangepi_mini_defconfig               |   1 -
 configs/Sinovoip_BPI_M3_defconfig             |   1 -
 configs/bananapi_m1_plus_defconfig            |   1 -
 configs/bananapi_m2_plus_h3_defconfig         |   1 -
 configs/bananapi_m2_plus_h5_defconfig         |   1 -
 configs/i12-tvbox_defconfig                   |   1 -
 configs/jesurun_q5_defconfig                  |   1 -
 configs/mangopi_mq_r_defconfig                |  12 +
 configs/mixtile_loftq_defconfig               |   1 -
 configs/nanopi_m1_plus_defconfig              |   1 -
 configs/nanopi_neo_plus2_defconfig            |   1 -
 configs/nanopi_r1s_h5_defconfig               |   1 -
 configs/orangepi_pc2_defconfig                |   1 -
 configs/orangepi_plus2e_defconfig             |   1 -
 configs/orangepi_plus_defconfig               |   2 -
 configs/orangepi_win_defconfig                |   1 -
 configs/pine_h64_defconfig                    |   1 -
 configs/zeropi_defconfig                      |   1 -
 drivers/ata/ahci_sunxi.c                      |   9 +
 drivers/clk/sunxi/Kconfig                     |   6 +
 drivers/clk/sunxi/Makefile                    |   1 +
 drivers/clk/sunxi/clk_d1.c                    | 101 +++
 drivers/gpio/axp_gpio.c                       |   1 +
 drivers/gpio/sunxi_gpio.c                     |  30 +-
 drivers/i2c/sun6i_p2wi.c                      |   2 +-
 drivers/i2c/sun8i_rsb.c                       |   2 +-
 drivers/mmc/sunxi_mmc.c                       |  12 +-
 drivers/net/sun8i_emac.c                      |   9 +-
 drivers/net/sunxi_emac.c                      |  10 +-
 drivers/pinctrl/sunxi/Kconfig                 |   5 +
 drivers/pinctrl/sunxi/pinctrl-sunxi.c         |  43 +-
 drivers/video/hitachi_tx18d42vm_lcd.c         |   1 +
 drivers/video/ssd2828.c                       |   1 -
 drivers/video/sunxi/sunxi_display.c           |   1 +
 drivers/video/sunxi/sunxi_lcd.c               |   1 +
 include/configs/sunxi-common.h                |   2 +-
 include/dt-bindings/clock/sun20i-d1-ccu.h     | 156 ++++
 include/dt-bindings/clock/sun20i-d1-r-ccu.h   |  19 +
 include/dt-bindings/reset/sun20i-d1-ccu.h     |  77 ++
 include/dt-bindings/reset/sun20i-d1-r-ccu.h   |  16 +
 .../arch-sunxi/gpio.h => include/sunxi_gpio.h | 102 ++-
 99 files changed, 1936 insertions(+), 296 deletions(-)
 create mode 100644 arch/arm/dts/sun8i-t113s-mangopi-mq-r.dts
 create mode 100644 arch/arm/dts/sun8i-t113s.dtsi
 create mode 100644 arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h
 create mode 100644 arch/arm/include/asm/arch-sunxi/serial.h
 delete mode 100644 arch/arm/mach-sunxi/pinmux.c
 create mode 100644 arch/riscv/dts/sun20i-d1.dtsi
 create mode 100644 arch/riscv/dts/sun20i-d1s.dtsi
 create mode 100644 arch/riscv/dts/sunxi-d1-t113.dtsi
 create mode 100644 arch/riscv/dts/sunxi-d1s-t113.dtsi
 create mode 100644 board/sunxi/dram_sun8i_r528.c
 create mode 100644 board/sunxi/pinctrl.c
 create mode 100644 configs/mangopi_mq_r_defconfig
 create mode 100644 drivers/clk/sunxi/clk_d1.c
 create mode 100644 include/dt-bindings/clock/sun20i-d1-ccu.h
 create mode 100644 include/dt-bindings/clock/sun20i-d1-r-ccu.h
 create mode 100644 include/dt-bindings/reset/sun20i-d1-ccu.h
 create mode 100644 include/dt-bindings/reset/sun20i-d1-r-ccu.h
 rename arch/arm/include/asm/arch-sunxi/gpio.h => include/sunxi_gpio.h (74%)
Signature · 1 line
2.35.5
#1 lore raw

RFC PATCH 1/17 sunxi: remove CONFIG_SATAPWR

The CONFIG_SATAPWR Kconfig symbol was used to point to a GPIO that enables the power for a SATA harddisk.
In the DT this is described with the target-supply property in the AHCI DT node, pointing to a (GPIO controlled) regulator. Since we need SATA only in U-Boot proper, and use a DM driver for AHCI there, we should use the DT instead of hardcoding this.

Add code to the sunxi AHCI driver to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the SATAPWR Kconfig definition and the respective values from the defconfigs.
We also select the generic fixed regulator driver, which handles those GPIO controlled regulators.

---
 arch/arm/Kconfig                             |  2 ++
 arch/arm/mach-sunxi/Kconfig                  |  8 --------
 board/sunxi/board.c                          | 14 --------------
 configs/A10-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino-Lime2-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino-Lime2_defconfig        |  1 -
 configs/A20-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino_MICRO-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino_MICRO_defconfig        |  1 -
 configs/A20-Olimex-SOM-EVB_defconfig         |  1 -
 configs/A20-Olimex-SOM204-EVB-eMMC_defconfig |  1 -
 configs/A20-Olimex-SOM204-EVB_defconfig      |  1 -
 configs/Cubieboard2_defconfig                |  1 -
 configs/Cubieboard_defconfig                 |  1 -
 configs/Cubietruck_defconfig                 |  1 -
 configs/Itead_Ibox_A20_defconfig             |  1 -
 configs/Lamobo_R1_defconfig                  |  1 -
 configs/Linksprite_pcDuino3_Nano_defconfig   |  1 -
 configs/Linksprite_pcDuino3_defconfig        |  1 -
 configs/Sinovoip_BPI_M3_defconfig            |  1 -
 configs/orangepi_plus_defconfig              |  1 -
 drivers/ata/ahci_sunxi.c                     |  9 +++++++++
 22 files changed, 11 insertions(+), 40 deletions(-)
arch/arm/Kconfig +2 -0
index f95ed71b246..3623520b353 100644
@@ -1148,6 +1148,8 @@ config ARCH_SUNXI
 	select DM_SPI_FLASH if SPI
 	select DM_KEYBOARD
 	select DM_MMC if MMC
+	select DM_REGULATOR
+	select DM_REGULATOR_FIXED
 	select DM_SCSI if SCSI
 	select DM_SERIAL
 	select GPIO_EXTRA_HEADER
arch/arm/mach-sunxi/Kconfig +0 -8
index dbe6005daab..5f95fe72d08 100644
@@ -985,14 +985,6 @@ config VIDEO_LCD_TL059WV5C0
 
 endchoice
 
-config SATAPWR
-	string "SATA power pin"
-	default ""
-	help
-	  Set the pins used to power the SATA. This takes a string in the
-	  format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of
-	  port H.
-
 config GMAC_TX_DELAY
 	int "GMAC Transmit Clock Delay Chain"
 	default 0
board/sunxi/board.c +0 -14
index 21a2407e062..ec35a7f06bd 100644
@@ -229,20 +229,6 @@ int board_init(void)
 		return ret;
 
 	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_SATAPWR[0]) {
-		satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
-		if (satapwr_pin >= 0) {
-			gpio_request(satapwr_pin, "satapwr");
-			gpio_direction_output(satapwr_pin, 1);
-
-			/*
-			 * Give the attached SATA device time to power-up
-			 * to avoid link timeouts
-			 */
-			mdelay(500);
-		}
-	}
-
 	if (CONFIG_MACPWR[0]) {
 		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
 		if (macpwr_pin >= 0) {
configs/A10-OLinuXino-Lime_defconfig +0 -1
index ee92ac45fbc..f5d98607003 100644
@@ -8,7 +8,6 @@ CONFIG_DRAM_EMR1=4
 CONFIG_SYS_CLK_FREQ=912000000
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime2-eMMC_defconfig +0 -1
index 8ce10d6f75b..a8e949a3971 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_SPL_SPI_SUNXI=y
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-OLinuXino-Lime2_defconfig +0 -1
index e38110b030b..c143cc17314 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime_defconfig +0 -1
index 4e4804748ef..b6546c26d04 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO-eMMC_defconfig +0 -1
index 113d54dc0b9..95860ef8fa1 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO_defconfig +0 -1
index 1e1c30ef303..32ca51554b1 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM-EVB_defconfig +0 -1
index e76e6dd0932..1364c42d865 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH0"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_USB0_VBUS_DET="PH5"
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM204-EVB-eMMC_defconfig +0 -1
index 1d3cf311952..77abe5c27ea 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-Olimex-SOM204-EVB_defconfig +0 -1
index 97d0b9cee75..19065fb18d0 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Cubieboard2_defconfig +0 -1
index 2c1b3d27aa0..40608498f38 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubieboard_defconfig +0 -1
index 008167509d3..9de9ee07568 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubietruck_defconfig +0 -1
index a4246343706..86588cdd5e2 100644
@@ -9,7 +9,6 @@ CONFIG_USB0_VBUS_PIN="PH17"
 CONFIG_USB0_VBUS_DET="PH22"
 CONFIG_USB0_ID_DET="PH19"
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PH12"
 CONFIG_GMAC_TX_DELAY=1
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Itead_Ibox_A20_defconfig +0 -1
index 6474c9e90a7..b52ce776251 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Lamobo_R1_defconfig +0 -1
index c943fd3c06e..d51601ff10f 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
 CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
-CONFIG_SATAPWR="PB3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_Nano_defconfig +0 -1
index 469dcc11f12..773f4a9e318 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=122
 CONFIG_USB1_VBUS_PIN="PH11"
-CONFIG_SATAPWR="PH2"
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_defconfig +0 -1
index c4a3f2db963..5b454b23864 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_DRAM_ZQ=122
-CONFIG_SATAPWR="PH2"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Sinovoip_BPI_M3_defconfig +0 -1
index ab70eff68eb..bcc8b1fba98 100644
@@ -13,7 +13,6 @@ CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
 CONFIG_USB0_ID_DET="PH11"
 CONFIG_USB1_VBUS_PIN="PD24"
 CONFIG_AXP_GPIO=y
-CONFIG_SATAPWR="PD25"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_CONSOLE_MUX=y
configs/orangepi_plus_defconfig +0 -1
index 5c7f0731d90..f4ce4851d7c 100644
@@ -7,7 +7,6 @@ CONFIG_DRAM_CLK=672
 CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
-CONFIG_SATAPWR="PG11"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_SPL_I2C=y
drivers/ata/ahci_sunxi.c +9 -0
index 94a3379c532..9064774e661 100644
@@ -7,6 +7,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <power/regulator.h>
 
 #define AHCI_PHYCS0R 0x00c0
 #define AHCI_PHYCS1R 0x00c4
@@ -74,6 +75,7 @@ static int sunxi_ahci_phy_init(u8 *reg_base)
 
 static int sunxi_sata_probe(struct udevice *dev)
 {
+	struct udevice *reg_dev;
 	ulong base;
 	u8 *reg;
 	int ret;
@@ -89,6 +91,13 @@ static int sunxi_sata_probe(struct udevice *dev)
 		debug("%s: Failed to init phy (err=%d)\n", __func__, ret);
 		return ret;
 	}
+
+	ret = device_get_supply_regulator(dev, "target-supply", &reg_dev);
+	if (ret == 0) {
+		regulator_set_enable(reg_dev, true);
+		mdelay(500);
+	}
+
 	ret = ahci_probe_scsi(dev, base);
 	if (ret) {
 		debug("%s: Failed to probe (err=%d)\n", __func__, ret);
Signature · 1 line
2.35.5
maintainer
#2 lore raw

Re: [RFC PATCH 01/17] sunxi: remove CONFIG_SATAPWR

Hi Andre,

Quoted 46 lines · Andre Przywara

The CONFIG_SATAPWR Kconfig symbol was used to point to a GPIO that enables the power for a SATA harddisk.
In the DT this is described with the target-supply property in the AHCI DT node, pointing to a (GPIO controlled) regulator. Since we need SATA only in U-Boot proper, and use a DM driver for AHCI there, we should use the DT instead of hardcoding this.

Add code to the sunxi AHCI driver to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the SATAPWR Kconfig definition and the respective values from the defconfigs.
We also select the generic fixed regulator driver, which handles those GPIO controlled regulators.

---
 arch/arm/Kconfig                             |  2 ++
 arch/arm/mach-sunxi/Kconfig                  |  8 --------
 board/sunxi/board.c                          | 14 --------------
 configs/A10-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino-Lime2-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino-Lime2_defconfig        |  1 -
 configs/A20-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino_MICRO-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino_MICRO_defconfig        |  1 -
 configs/A20-Olimex-SOM-EVB_defconfig         |  1 -
 configs/A20-Olimex-SOM204-EVB-eMMC_defconfig |  1 -
 configs/A20-Olimex-SOM204-EVB_defconfig      |  1 -
 configs/Cubieboard2_defconfig                |  1 -
 configs/Cubieboard_defconfig                 |  1 -
 configs/Cubietruck_defconfig                 |  1 -
 configs/Itead_Ibox_A20_defconfig             |  1 -
 configs/Lamobo_R1_defconfig                  |  1 -
 configs/Linksprite_pcDuino3_Nano_defconfig   |  1 -
 configs/Linksprite_pcDuino3_defconfig        |  1 -
 configs/Sinovoip_BPI_M3_defconfig            |  1 -
 configs/orangepi_plus_defconfig              |  1 -
 drivers/ata/ahci_sunxi.c                     |  9 +++++++++
 22 files changed, 11 insertions(+), 40 deletions(-)
arch/arm/Kconfig +0 -0
index f95ed71b246..3623520b353 100644

arch/arm/Kconfig config ARCH_SUNXI · line 1152

Quoted 5 lines
arch/arm/Kconfig +2 -0
@@ -1148,6 +1148,8 @@ config ARCH_SUNXI
 	select DM_SPI_FLASH if SPI
 	select DM_KEYBOARD
 	select DM_MMC if MMC
+	select DM_REGULATOR
+	select DM_REGULATOR_FIXED

While not all boards have fixed regulators, so many do that I am happy to have this driver enabled by default. However, I recommend "imply" over "select" so the regulator uclass can be disabled if USB/SATA/Ethernet/whatever are not being used. You also need to select/imply POWER, as it is a dependency.

Quoted 256 lines
arch/arm/Kconfig +0 -0
 	select DM_SCSI if SCSI
 	select DM_SERIAL
 	select GPIO_EXTRA_HEADER
arch/arm/mach-sunxi/Kconfig +0 -8
index dbe6005daab..5f95fe72d08 100644
@@ -985,14 +985,6 @@ config VIDEO_LCD_TL059WV5C0
 
 endchoice
 
-config SATAPWR
-	string "SATA power pin"
-	default ""
-	help
-	  Set the pins used to power the SATA. This takes a string in the
-	  format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of
-	  port H.
-
 config GMAC_TX_DELAY
 	int "GMAC Transmit Clock Delay Chain"
 	default 0
board/sunxi/board.c +0 -14
index 21a2407e062..ec35a7f06bd 100644
@@ -229,20 +229,6 @@ int board_init(void)
 		return ret;
 
 	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_SATAPWR[0]) {
-		satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
-		if (satapwr_pin >= 0) {
-			gpio_request(satapwr_pin, "satapwr");
-			gpio_direction_output(satapwr_pin, 1);
-
-			/*
-			 * Give the attached SATA device time to power-up
-			 * to avoid link timeouts
-			 */
-			mdelay(500);
-		}
-	}
-
 	if (CONFIG_MACPWR[0]) {
 		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
 		if (macpwr_pin >= 0) {
configs/A10-OLinuXino-Lime_defconfig +0 -1
index ee92ac45fbc..f5d98607003 100644
@@ -8,7 +8,6 @@ CONFIG_DRAM_EMR1=4
 CONFIG_SYS_CLK_FREQ=912000000
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime2-eMMC_defconfig +0 -1
index 8ce10d6f75b..a8e949a3971 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_SPL_SPI_SUNXI=y
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-OLinuXino-Lime2_defconfig +0 -1
index e38110b030b..c143cc17314 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime_defconfig +0 -1
index 4e4804748ef..b6546c26d04 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO-eMMC_defconfig +0 -1
index 113d54dc0b9..95860ef8fa1 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO_defconfig +0 -1
index 1e1c30ef303..32ca51554b1 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM-EVB_defconfig +0 -1
index e76e6dd0932..1364c42d865 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH0"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_USB0_VBUS_DET="PH5"
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM204-EVB-eMMC_defconfig +0 -1
index 1d3cf311952..77abe5c27ea 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-Olimex-SOM204-EVB_defconfig +0 -1
index 97d0b9cee75..19065fb18d0 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Cubieboard2_defconfig +0 -1
index 2c1b3d27aa0..40608498f38 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubieboard_defconfig +0 -1
index 008167509d3..9de9ee07568 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubietruck_defconfig +0 -1
index a4246343706..86588cdd5e2 100644
@@ -9,7 +9,6 @@ CONFIG_USB0_VBUS_PIN="PH17"
 CONFIG_USB0_VBUS_DET="PH22"
 CONFIG_USB0_ID_DET="PH19"
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PH12"
 CONFIG_GMAC_TX_DELAY=1
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Itead_Ibox_A20_defconfig +0 -1
index 6474c9e90a7..b52ce776251 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Lamobo_R1_defconfig +0 -1
index c943fd3c06e..d51601ff10f 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
 CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
-CONFIG_SATAPWR="PB3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_Nano_defconfig +0 -1
index 469dcc11f12..773f4a9e318 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=122
 CONFIG_USB1_VBUS_PIN="PH11"
-CONFIG_SATAPWR="PH2"
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_defconfig +0 -1
index c4a3f2db963..5b454b23864 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_DRAM_ZQ=122
-CONFIG_SATAPWR="PH2"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Sinovoip_BPI_M3_defconfig +0 -1
index ab70eff68eb..bcc8b1fba98 100644
@@ -13,7 +13,6 @@ CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
 CONFIG_USB0_ID_DET="PH11"
 CONFIG_USB1_VBUS_PIN="PD24"
 CONFIG_AXP_GPIO=y
-CONFIG_SATAPWR="PD25"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_CONSOLE_MUX=y
configs/orangepi_plus_defconfig +0 -0
index 5c7f0731d90..f4ce4851d7c 100644

configs/orangepi_plus_defconfig CONFIG_DRAM_CLK=672 · line 10

Quoted 4 lines
configs/orangepi_plus_defconfig +0 -1
@@ -7,7 +7,6 @@ CONFIG_DRAM_CLK=672
 CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
-CONFIG_SATAPWR="PG11"

BananaPi M3 and OrangePi Plus have USB-SATA adapters, not onboard AHCI, so they would lose the ability to use SATA with this change.

OrangePi Plus has the SATA controller regulator as usb3_vbus-supply in its devicetree. So we could replace this with CONFIG_USB3_VBUS_PIN for now, and it will continue to work once we switch the PHY driver to use the regulator uclass.

But the BananaPi M3 has its USB-SATA downstream from an external hub. CONFIG_USB1_VBUS_PIN is used for the regulator powering the hub, so I do not see an obvious solution here.

Regards,
Samuel

Quoted 37 lines
configs/orangepi_plus_defconfig +0 -0
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_SPL_I2C=y
drivers/ata/ahci_sunxi.c +9 -0
index 94a3379c532..9064774e661 100644
@@ -7,6 +7,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <power/regulator.h>
 
 #define AHCI_PHYCS0R 0x00c0
 #define AHCI_PHYCS1R 0x00c4
@@ -74,6 +75,7 @@ static int sunxi_ahci_phy_init(u8 *reg_base)
 
 static int sunxi_sata_probe(struct udevice *dev)
 {
+	struct udevice *reg_dev;
 	ulong base;
 	u8 *reg;
 	int ret;
@@ -89,6 +91,13 @@ static int sunxi_sata_probe(struct udevice *dev)
 		debug("%s: Failed to init phy (err=%d)\n", __func__, ret);
 		return ret;
 	}
+
+	ret = device_get_supply_regulator(dev, "target-supply", &reg_dev);
+	if (ret == 0) {
+		regulator_set_enable(reg_dev, true);
+		mdelay(500);
+	}
+
 	ret = ahci_probe_scsi(dev, base);
 	if (ret) {
 		debug("%s: Failed to probe (err=%d)\n", __func__, ret);
#3 lore raw

Re: [RFC PATCH 01/17] sunxi: remove CONFIG_SATAPWR

On Wed, 14 Dec 2022 02:37:12 -0600
Samuel Holland <[email protected]> wrote:

Hi Samuel,

many thanks for having a look!

Quoted 42 lines · Andre Przywara
Quoted 41 lines

The CONFIG_SATAPWR Kconfig symbol was used to point to a GPIO that enables the power for a SATA harddisk.
In the DT this is described with the target-supply property in the AHCI DT node, pointing to a (GPIO controlled) regulator. Since we need SATA only in U-Boot proper, and use a DM driver for AHCI there, we should use the DT instead of hardcoding this.

Add code to the sunxi AHCI driver to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the SATAPWR Kconfig definition and the respective values from the defconfigs.
We also select the generic fixed regulator driver, which handles those GPIO controlled regulators.

---
 arch/arm/Kconfig                             |  2 ++
 arch/arm/mach-sunxi/Kconfig                  |  8 --------
 board/sunxi/board.c                          | 14 --------------
 configs/A10-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino-Lime2-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino-Lime2_defconfig        |  1 -
 configs/A20-OLinuXino-Lime_defconfig         |  1 -
 configs/A20-OLinuXino_MICRO-eMMC_defconfig   |  1 -
 configs/A20-OLinuXino_MICRO_defconfig        |  1 -
 configs/A20-Olimex-SOM-EVB_defconfig         |  1 -
 configs/A20-Olimex-SOM204-EVB-eMMC_defconfig |  1 -
 configs/A20-Olimex-SOM204-EVB_defconfig      |  1 -
 configs/Cubieboard2_defconfig                |  1 -
 configs/Cubieboard_defconfig                 |  1 -
 configs/Cubietruck_defconfig                 |  1 -
 configs/Itead_Ibox_A20_defconfig             |  1 -
 configs/Lamobo_R1_defconfig                  |  1 -
 configs/Linksprite_pcDuino3_Nano_defconfig   |  1 -
 configs/Linksprite_pcDuino3_defconfig        |  1 -
 configs/Sinovoip_BPI_M3_defconfig            |  1 -
 configs/orangepi_plus_defconfig              |  1 -
 drivers/ata/ahci_sunxi.c                     |  9 +++++++++
 22 files changed, 11 insertions(+), 40 deletions(-)
Quoted 16 lines

arch/arm/Kconfig config ARCH_SUNXI · line 1152

Quoted 10 lines
arch/arm/Kconfig +2 -0
index f95ed71b246..3623520b353 100644
@@ -1148,6 +1148,8 @@ config ARCH_SUNXI
 	select DM_SPI_FLASH if SPI
 	select DM_KEYBOARD
 	select DM_MMC if MMC
+	select DM_REGULATOR
+	select DM_REGULATOR_FIXED  

While not all boards have fixed regulators, so many do that I am happy to have this driver enabled by default. However, I recommend "imply" over "select" so the regulator uclass can be disabled if USB/SATA/Ethernet/whatever are not being used. You also need to select/imply POWER, as it is a dependency.

Yes, that's indeed better.

Quoted 255 lines
Quoted 255 lines
arch/arm/Kconfig +0 -0
 	select DM_SCSI if SCSI
 	select DM_SERIAL
 	select GPIO_EXTRA_HEADER
arch/arm/mach-sunxi/Kconfig +0 -8
index dbe6005daab..5f95fe72d08 100644
@@ -985,14 +985,6 @@ config VIDEO_LCD_TL059WV5C0
 
 endchoice
 
-config SATAPWR
-	string "SATA power pin"
-	default ""
-	help
-	  Set the pins used to power the SATA. This takes a string in the
-	  format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of
-	  port H.
-
 config GMAC_TX_DELAY
 	int "GMAC Transmit Clock Delay Chain"
 	default 0
board/sunxi/board.c +0 -14
index 21a2407e062..ec35a7f06bd 100644
@@ -229,20 +229,6 @@ int board_init(void)
 		return ret;
 
 	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_SATAPWR[0]) {
-		satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
-		if (satapwr_pin >= 0) {
-			gpio_request(satapwr_pin, "satapwr");
-			gpio_direction_output(satapwr_pin, 1);
-
-			/*
-			 * Give the attached SATA device time to power-up
-			 * to avoid link timeouts
-			 */
-			mdelay(500);
-		}
-	}
-
 	if (CONFIG_MACPWR[0]) {
 		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
 		if (macpwr_pin >= 0) {
configs/A10-OLinuXino-Lime_defconfig +0 -1
index ee92ac45fbc..f5d98607003 100644
@@ -8,7 +8,6 @@ CONFIG_DRAM_EMR1=4
 CONFIG_SYS_CLK_FREQ=912000000
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime2-eMMC_defconfig +0 -1
index 8ce10d6f75b..a8e949a3971 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_SPL_SPI_SUNXI=y
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-OLinuXino-Lime2_defconfig +0 -1
index e38110b030b..c143cc17314 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino-Lime_defconfig +0 -1
index 4e4804748ef..b6546c26d04 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
 CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO-eMMC_defconfig +0 -1
index 113d54dc0b9..95860ef8fa1 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-OLinuXino_MICRO_defconfig +0 -1
index 1e1c30ef303..32ca51554b1 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_I2C1_ENABLE=y
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM-EVB_defconfig +0 -1
index e76e6dd0932..1364c42d865 100644
@@ -9,7 +9,6 @@ CONFIG_MMC3_CD_PIN="PH0"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_USB0_VBUS_DET="PH5"
-CONFIG_SATAPWR="PC3"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/A20-Olimex-SOM204-EVB-eMMC_defconfig +0 -1
index 1d3cf311952..77abe5c27ea 100644
@@ -9,7 +9,6 @@ CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/A20-Olimex-SOM204-EVB_defconfig +0 -1
index 97d0b9cee75..19065fb18d0 100644
@@ -8,7 +8,6 @@ CONFIG_MMC0_CD_PIN="PH1"
 CONFIG_USB0_VBUS_PIN="PC17"
 CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_I2C1_ENABLE=y
-CONFIG_SATAPWR="PC3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Cubieboard2_defconfig +0 -1
index 2c1b3d27aa0..40608498f38 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubieboard_defconfig +0 -1
index 008167509d3..9de9ee07568 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Cubietruck_defconfig +0 -1
index a4246343706..86588cdd5e2 100644
@@ -9,7 +9,6 @@ CONFIG_USB0_VBUS_PIN="PH17"
 CONFIG_USB0_VBUS_DET="PH22"
 CONFIG_USB0_ID_DET="PH19"
 CONFIG_VIDEO_VGA=y
-CONFIG_SATAPWR="PH12"
 CONFIG_GMAC_TX_DELAY=1
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Itead_Ibox_A20_defconfig +0 -1
index 6474c9e90a7..b52ce776251 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_MMC0_CD_PIN="PH1"
-CONFIG_SATAPWR="PB8"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Lamobo_R1_defconfig +0 -1
index c943fd3c06e..d51601ff10f 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
 CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
-CONFIG_SATAPWR="PB3"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_Nano_defconfig +0 -1
index 469dcc11f12..773f4a9e318 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=122
 CONFIG_USB1_VBUS_PIN="PH11"
-CONFIG_SATAPWR="PH2"
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/Linksprite_pcDuino3_defconfig +0 -1
index c4a3f2db963..5b454b23864 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=480
 CONFIG_DRAM_ZQ=122
-CONFIG_SATAPWR="PH2"
 CONFIG_AHCI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/Sinovoip_BPI_M3_defconfig +0 -1
index ab70eff68eb..bcc8b1fba98 100644
@@ -13,7 +13,6 @@ CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
 CONFIG_USB0_ID_DET="PH11"
 CONFIG_USB1_VBUS_PIN="PD24"
 CONFIG_AXP_GPIO=y
-CONFIG_SATAPWR="PD25"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_CONSOLE_MUX=y
configs/orangepi_plus_defconfig +0 -0
index 5c7f0731d90..f4ce4851d7c 100644
Quoted 8 lines

configs/orangepi_plus_defconfig CONFIG_DRAM_CLK=672 · line 10

Quoted 5 lines
configs/orangepi_plus_defconfig +0 -1
@@ -7,7 +7,6 @@ CONFIG_DRAM_CLK=672
 CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
-CONFIG_SATAPWR="PG11"  

BananaPi M3 and OrangePi Plus have USB-SATA adapters, not onboard AHCI, so they would lose the ability to use SATA with this change.

Many thanks for having a thorough look, I much appreciate that. Of course you are right. I actually found this myself, and thought I mentioned it somewhere, but apparently this got lost in between cover letter versions and commit messages on different branches. Apologies for that.
So yeah, my research figured that this isn't described properly in the DT, so SATA disks just work in Linux because U-Boot flipped the bit here. I heard about USB child DT nodes, which IIUC are possible to describe errata and such, but I don't think it's a good solution here. Would probably need driver changes, so wouldn't be backwards compatible.

Quoted 8 lines

OrangePi Plus has the SATA controller regulator as usb3_vbus-supply in its devicetree. So we could replace this with CONFIG_USB3_VBUS_PIN for now, and it will continue to work once we switch the PHY driver to use the regulator uclass.

But the BananaPi M3 has its USB-SATA downstream from an external hub. CONFIG_USB1_VBUS_PIN is used for the regulator powering the hub, so I do not see an obvious solution here.

Yeah, I didn't find a neat automatic solution for that either. Can we add a regulator-fixed, and make this regulator-boot-on? Without actually referencing this regulator anywhere? I need to check this actually works in U-Boot, but what do you say with your Linux/DT maintainer hat on?

Cheers,
Andre

Quoted 38 lines
Quoted 37 lines
configs/orangepi_plus_defconfig +0 -0
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_SPL_I2C=y
drivers/ata/ahci_sunxi.c +9 -0
index 94a3379c532..9064774e661 100644
@@ -7,6 +7,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
+#include <power/regulator.h>
 
 #define AHCI_PHYCS0R 0x00c0
 #define AHCI_PHYCS1R 0x00c4
@@ -74,6 +75,7 @@ static int sunxi_ahci_phy_init(u8 *reg_base)
 
 static int sunxi_sata_probe(struct udevice *dev)
 {
+	struct udevice *reg_dev;
 	ulong base;
 	u8 *reg;
 	int ret;
@@ -89,6 +91,13 @@ static int sunxi_sata_probe(struct udevice *dev)
 		debug("%s: Failed to init phy (err=%d)\n", __func__, ret);
 		return ret;
 	}
+
+	ret = device_get_supply_regulator(dev, "target-supply", &reg_dev);
+	if (ret == 0) {
+		regulator_set_enable(reg_dev, true);
+		mdelay(500);
+	}
+
 	ret = ahci_probe_scsi(dev, base);
 	if (ret) {
 		debug("%s: Failed to probe (err=%d)\n", __func__, ret);  
maintainer
#4 lore raw

Re: [RFC PATCH 01/17] sunxi: remove CONFIG_SATAPWR

Andre,

Quoted 47 lines · Andre Przywara
Quoted 17 lines · On Wed, 14 Dec 2022 02:37:12 -0600 Samuel Holland <[email protected]> wrote:
Quoted 16 lines · Andre Przywara
configs/Sinovoip_BPI_M3_defconfig +0 -1
index ab70eff68eb..bcc8b1fba98 100644
@@ -13,7 +13,6 @@ CONFIG_USB0_VBUS_DET="AXP0-VBUS-DETECT"
 CONFIG_USB0_ID_DET="PH11"
 CONFIG_USB1_VBUS_PIN="PD24"
 CONFIG_AXP_GPIO=y
-CONFIG_SATAPWR="PD25"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
 CONFIG_CONSOLE_MUX=y
configs/orangepi_plus_defconfig +0 -0
index 5c7f0731d90..f4ce4851d7c 100644
Quoted 8 lines

configs/orangepi_plus_defconfig CONFIG_DRAM_CLK=672 · line 10

Quoted 5 lines
configs/orangepi_plus_defconfig +0 -1
@@ -7,7 +7,6 @@ CONFIG_DRAM_CLK=672
 CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
-CONFIG_SATAPWR="PG11"  

BananaPi M3 and OrangePi Plus have USB-SATA adapters, not onboard AHCI, so they would lose the ability to use SATA with this change.

Many thanks for having a thorough look, I much appreciate that. Of course you are right. I actually found this myself, and thought I mentioned it somewhere, but apparently this got lost in between cover letter versions and commit messages on different branches. Apologies for that.
So yeah, my research figured that this isn't described properly in the DT, so SATA disks just work in Linux because U-Boot flipped the bit here. I heard about USB child DT nodes, which IIUC are possible to describe errata and such, but I don't think it's a good solution here. Would probably need driver changes, so wouldn't be backwards compatible.

Quoted 8 lines

OrangePi Plus has the SATA controller regulator as usb3_vbus-supply in its devicetree. So we could replace this with CONFIG_USB3_VBUS_PIN for now, and it will continue to work once we switch the PHY driver to use the regulator uclass.

But the BananaPi M3 has its USB-SATA downstream from an external hub. CONFIG_USB1_VBUS_PIN is used for the regulator powering the hub, so I do not see an obvious solution here.

Quoted 5 lines

Yeah, I didn't find a neat automatic solution for that either. Can we add a regulator-fixed, and make this regulator-boot-on? Without actually referencing this regulator anywhere? I need to check this actually works in U-Boot, but what do you say with your Linux/DT maintainer hat on?

I can think of a few solutions, though none is perfect:

1) As you suggest, add a new fixed regulator with regulator-boot-on. It also needs regulator-always-on to keep the OS from disabling it later, since it would have no consumer. We would also need to call regulators_enable_boot_on() from our board code to enable in in U-Boot.

2) Add a new fixed regulator, and point usb1_vbus-supply to it. Then have the new regulator reference the hub regulator as its vin-supply. This would require updating the U-Boot fixed regulator driver to control its vin-supply. And it is also a misleading use of usb1_vbus-supply.

3) Add a gpio-hog to the devicetree, to unconditionally enable the regulator. This would be the closest equivalent to what we are doing now, and the quickest path to getting the legacy board code removed. We could do this entirely within U-Boot, so I lean toward this solution.

Regards,
Samuel

#5 lore raw

RFC PATCH 2/17 sunxi: remove CONFIG_MACPWR

In reply to Andre Przywara

The CONFIG_MACPWR Kconfig symbol is used to point to a GPIO that enables the power for the Ethernet "MAC" (mostly PHY, really).
In the DT this is described with the phy-supply property in the MAC DT node, pointing to a (GPIO controlled) regulator. Since we need Ethernet only in U-Boot proper, and use a DM driver there, we should use the DT instead of hardcoding this.

Add code to the sun8i_emac and sunxi_emac drivers to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the MACPWR Kconfig definition and the respective values from the defconfigs.

---
 arch/arm/mach-sunxi/Kconfig           |  7 -------
 board/sunxi/board.c                   | 10 ----------
 configs/Bananapi_M2_Ultra_defconfig   |  1 -
 configs/Bananapi_defconfig            |  1 -
 configs/Bananapro_defconfig           |  1 -
 configs/Lamobo_R1_defconfig           |  1 -
 configs/Mele_A1000_defconfig          |  1 -
 configs/Orangepi_defconfig            |  1 -
 configs/Orangepi_mini_defconfig       |  1 -
 configs/bananapi_m1_plus_defconfig    |  1 -
 configs/bananapi_m2_plus_h3_defconfig |  1 -
 configs/bananapi_m2_plus_h5_defconfig |  1 -
 configs/i12-tvbox_defconfig           |  1 -
 configs/jesurun_q5_defconfig          |  1 -
 configs/mixtile_loftq_defconfig       |  1 -
 configs/nanopi_m1_plus_defconfig      |  1 -
 configs/nanopi_neo_plus2_defconfig    |  1 -
 configs/nanopi_r1s_h5_defconfig       |  1 -
 configs/orangepi_pc2_defconfig        |  1 -
 configs/orangepi_plus2e_defconfig     |  1 -
 configs/orangepi_plus_defconfig       |  1 -
 configs/orangepi_win_defconfig        |  1 -
 configs/pine_h64_defconfig            |  1 -
 configs/zeropi_defconfig              |  1 -
 drivers/net/sun8i_emac.c              |  9 +++++++--
 drivers/net/sunxi_emac.c              | 10 ++++++++--
 26 files changed, 15 insertions(+), 43 deletions(-)
arch/arm/mach-sunxi/Kconfig +0 -7
index 5f95fe72d08..6220175d612 100644
@@ -645,13 +645,6 @@ config OLD_SUNXI_KERNEL_COMPAT
 	Set this to enable various workarounds for old kernels, this results in
 	sub-optimal settings for newer kernels, only enable if needed.
 
-config MACPWR
-	string "MAC power pin"
-	default ""
-	help
-	  Set the pin used to power the MAC. This takes a string in the format
-	  understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
-
 config MMC0_CD_PIN
 	string "Card detect pin for mmc0"
 	default "PF6" if MACH_SUN8I_A83T || MACH_SUNXI_H3_H5 || MACH_SUN50I
board/sunxi/board.c +0 -10
index ec35a7f06bd..3077cc71ebd 100644
@@ -228,15 +228,6 @@ int board_init(void)
 	if (ret)
 		return ret;
 
-	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_MACPWR[0]) {
-		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
-		if (macpwr_pin >= 0) {
-			gpio_request(macpwr_pin, "macpwr");
-			gpio_direction_output(macpwr_pin, 1);
-		}
-	}
-
 #if CONFIG_IS_ENABLED(DM_I2C)
 	/*
 	 * Temporary workaround for enabling I2C clocks until proper sunxi DM
@@ -244,7 +235,6 @@ int board_init(void)
 	 */
 	i2c_init_board();
 #endif
-
 	eth_init_board();
 
 	return 0;
configs/Bananapi_M2_Ultra_defconfig +0 -1
index 0bd163afdd7..1c4b90ab9d2 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r40-bananapi-m2-ultra"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_R40=y
 CONFIG_DRAM_CLK=576
-CONFIG_MACPWR="PA17"
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH23"
configs/Bananapi_defconfig +0 -1
index 2814d77c187..2a590e141d9 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/Bananapro_defconfig +0 -1
index 11375991c81..4b56195d4f2 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapro"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH0"
 CONFIG_USB2_VBUS_PIN="PH1"
 CONFIG_VIDEO_COMPOSITE=y
configs/Lamobo_R1_defconfig +0 -1
index d51601ff10f..fc63a7fbd46 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-lamobo-r1"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
configs/Mele_A1000_defconfig +0 -1
index 3424b976772..a407550f6bd 100644
@@ -3,7 +3,6 @@ CONFIG_ARCH_SUNXI=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-a1000"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
-CONFIG_MACPWR="PH15"
 CONFIG_VIDEO_VGA=y
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_AHCI=y
configs/Orangepi_defconfig +0 -1
index b4d5feff309..5c14e327e39 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH26"
 CONFIG_USB2_VBUS_PIN="PH22"
 CONFIG_VIDEO_VGA=y
configs/Orangepi_mini_defconfig +0 -1
index 43197381114..fdacf0cd123 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi-mini"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
configs/bananapi_m1_plus_defconfig +0 -1
index 12ea6a3236a..f398c70ce1a 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/bananapi_m2_plus_h3_defconfig +0 -1
index 2bd5a70a2d0..ab138a43060 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/bananapi_m2_plus_h5_defconfig +0 -1
index 926cf6f5a4d..29200e53585 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h5-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/i12-tvbox_defconfig +0 -1
index d75a7992a82..11971a8a766 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-i12-tvbox"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
-CONFIG_MACPWR="PH21"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/jesurun_q5_defconfig +0 -1
index 2e6b045b549..701d8ecfaa8 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-jesurun-q5"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=312
-CONFIG_MACPWR="PH19"
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/mixtile_loftq_defconfig +0 -1
index 646594b6e07..cdee80b3566 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq"
 CONFIG_SPL=y
 CONFIG_MACH_SUN6I=y
 CONFIG_DRAM_ZQ=251
-CONFIG_MACPWR="PA21"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH24"
 CONFIG_USB2_VBUS_PIN=""
configs/nanopi_m1_plus_defconfig +0 -1
index 89065f0411a..a3b82de4de6 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-nanopi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/nanopi_neo_plus2_defconfig +0 -1
index d462b63e944..f7e3efdfe5e 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/nanopi_r1s_h5_defconfig +0 -1
index 5c332ca5261..760dfe37022 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_pc2_defconfig +0 -1
index 356ae7ce476..cf75cf4b351 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
-CONFIG_MACPWR="PD6"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus2e_defconfig +0 -1
index e27b329b0a9..c72adfb3e69 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus2e"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus_defconfig +0 -1
index f4ce4851d7c..c407af38bcc 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/orangepi_win_defconfig +0 -1
index 1e26970230f..b803dcd01ef 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-orangepi-win"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I=y
 CONFIG_RESERVE_ALLWINNER_BOOT0_HEADER=y
-CONFIG_MACPWR="PD14"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/pine_h64_defconfig +0 -1
index 578bd92f6a3..0b482dcea24 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-pine-h64"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H6=y
 CONFIG_SUNXI_DRAM_H6_LPDDR3=y
-CONFIG_MACPWR="PC16"
 CONFIG_MMC0_CD_PIN="PF6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB3_VBUS_PIN="PL5"
configs/zeropi_defconfig +0 -1
index 8365da2c472..7ace1b5cbfd 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-zeropi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 # CONFIG_VIDEO_DE2 is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
drivers/net/sun8i_emac.c +7 -2
index 9cca8fa4e0a..c7087b7302d 100644
@@ -29,6 +29,7 @@
 #include <net.h>
 #include <reset.h>
 #include <wait_bit.h>
+#include <power/regulator.h>
 
 #define MDIO_CMD_MII_BUSY		BIT(0)
 #define MDIO_CMD_MII_WRITE		BIT(1)
@@ -169,9 +170,8 @@ struct emac_eth_dev {
 	struct clk ephy_clk;
 	struct reset_ctl tx_rst;
 	struct reset_ctl ephy_rst;
-#if CONFIG_IS_ENABLED(DM_GPIO)
 	struct gpio_desc reset_gpio;
-#endif
+	struct udevice *phy_reg;
 };
 
 
@@ -738,6 +738,9 @@ static int sun8i_emac_eth_probe(struct udevice *dev)
 
 	sun8i_emac_set_syscon(sun8i_pdata, priv);
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	sun8i_mdio_init(dev->name, dev);
 	priv->bus = miiphy_get_dev_by_name(dev->name);
 
@@ -844,6 +847,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
 		return -EINVAL;
 	}
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);
+
 	pdata->phy_interface = -1;
 	priv->phyaddr = -1;
 	priv->use_internal_phy = false;
drivers/net/sunxi_emac.c +8 -2
index 8625e49dae4..ee8b8a1667d 100644
@@ -17,6 +17,7 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <power/regulator.h>
 
 /* EMAC register  */
 struct emac_regs {
@@ -164,9 +165,8 @@ struct emac_eth_dev {
 	struct mii_dev *bus;
 	struct phy_device *phydev;
 	int link_printed;
-#ifdef CONFIG_DM_ETH
 	uchar rx_buf[EMAC_RX_BUFSIZE];
-#endif
+	struct udevice *phy_reg;
 };
 
 struct emac_rxhdr {
@@ -575,6 +575,9 @@ static int sunxi_emac_eth_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	return sunxi_emac_init_phy(priv, dev);
 }
 
@@ -588,9 +591,12 @@ static const struct eth_ops sunxi_emac_eth_ops = {
 static int sunxi_emac_eth_of_to_plat(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
+	struct emac_eth_dev *priv = dev_get_priv(dev);
 
 	pdata->iobase = dev_read_addr(dev);
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);
+
 	return 0;
 }
 
Signature · 1 line
2.35.5
maintainer
#6 lore raw

Re: [RFC PATCH 02/17] sunxi: remove CONFIG_MACPWR

Hi Andre,

Thanks for this cleanup! With the two issues below addressed, it looks good to me.

Quoted 7 lines · Andre Przywara

The CONFIG_MACPWR Kconfig symbol is used to point to a GPIO that enables the power for the Ethernet "MAC" (mostly PHY, really).
In the DT this is described with the phy-supply property in the MAC DT node, pointing to a (GPIO controlled) regulator. Since we need Ethernet only in U-Boot proper, and use a DM driver there, we should use the DT instead of hardcoding this.

Quoted 5 lines

Add code to the sun8i_emac and sunxi_emac drivers to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the MACPWR Kconfig definition and the respective values from the defconfigs.

... and we don't care about sun7i-gmac here because there's no U-Boot driver for it, and the Linux driver already uses the devicetree.

Quoted 81 lines
---
 arch/arm/mach-sunxi/Kconfig           |  7 -------
 board/sunxi/board.c                   | 10 ----------
 configs/Bananapi_M2_Ultra_defconfig   |  1 -
 configs/Bananapi_defconfig            |  1 -
 configs/Bananapro_defconfig           |  1 -
 configs/Lamobo_R1_defconfig           |  1 -
 configs/Mele_A1000_defconfig          |  1 -
 configs/Orangepi_defconfig            |  1 -
 configs/Orangepi_mini_defconfig       |  1 -
 configs/bananapi_m1_plus_defconfig    |  1 -
 configs/bananapi_m2_plus_h3_defconfig |  1 -
 configs/bananapi_m2_plus_h5_defconfig |  1 -
 configs/i12-tvbox_defconfig           |  1 -
 configs/jesurun_q5_defconfig          |  1 -
 configs/mixtile_loftq_defconfig       |  1 -
 configs/nanopi_m1_plus_defconfig      |  1 -
 configs/nanopi_neo_plus2_defconfig    |  1 -
 configs/nanopi_r1s_h5_defconfig       |  1 -
 configs/orangepi_pc2_defconfig        |  1 -
 configs/orangepi_plus2e_defconfig     |  1 -
 configs/orangepi_plus_defconfig       |  1 -
 configs/orangepi_win_defconfig        |  1 -
 configs/pine_h64_defconfig            |  1 -
 configs/zeropi_defconfig              |  1 -
 drivers/net/sun8i_emac.c              |  9 +++++++--
 drivers/net/sunxi_emac.c              | 10 ++++++++--
 26 files changed, 15 insertions(+), 43 deletions(-)
arch/arm/mach-sunxi/Kconfig +0 -7
index 5f95fe72d08..6220175d612 100644
@@ -645,13 +645,6 @@ config OLD_SUNXI_KERNEL_COMPAT
 	Set this to enable various workarounds for old kernels, this results in
 	sub-optimal settings for newer kernels, only enable if needed.
 
-config MACPWR
-	string "MAC power pin"
-	default ""
-	help
-	  Set the pin used to power the MAC. This takes a string in the format
-	  understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
-
 config MMC0_CD_PIN
 	string "Card detect pin for mmc0"
 	default "PF6" if MACH_SUN8I_A83T || MACH_SUNXI_H3_H5 || MACH_SUN50I
board/sunxi/board.c +0 -10
index ec35a7f06bd..3077cc71ebd 100644
@@ -228,15 +228,6 @@ int board_init(void)
 	if (ret)
 		return ret;
 
-	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_MACPWR[0]) {
-		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
-		if (macpwr_pin >= 0) {
-			gpio_request(macpwr_pin, "macpwr");
-			gpio_direction_output(macpwr_pin, 1);
-		}
-	}
-
 #if CONFIG_IS_ENABLED(DM_I2C)
 	/*
 	 * Temporary workaround for enabling I2C clocks until proper sunxi DM
@@ -244,7 +235,6 @@ int board_init(void)
 	 */
 	i2c_init_board();
 #endif
-
 	eth_init_board();
 
 	return 0;
configs/Bananapi_M2_Ultra_defconfig +0 -0
index 0bd163afdd7..1c4b90ab9d2 100644

configs/Bananapi_M2_Ultra_defconfig CONFIG_DEFAULT_DEVICE_TREE="sun8i-r40-bananapi-m2-ultra" · line 7

Quoted 4 lines
configs/Bananapi_M2_Ultra_defconfig +0 -1
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r40-bananapi-m2-ultra"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_R40=y
 CONFIG_DRAM_CLK=576
-CONFIG_MACPWR="PA17"

This GPIO is actually the PHY reset line, not its power supply. Since that line has a pull up, I don't think this was necessary to begin with.

Quoted 140 lines
configs/Bananapi_M2_Ultra_defconfig +0 -0
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH23"
configs/Bananapi_defconfig +0 -1
index 2814d77c187..2a590e141d9 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/Bananapro_defconfig +0 -1
index 11375991c81..4b56195d4f2 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapro"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH0"
 CONFIG_USB2_VBUS_PIN="PH1"
 CONFIG_VIDEO_COMPOSITE=y
configs/Lamobo_R1_defconfig +0 -1
index d51601ff10f..fc63a7fbd46 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-lamobo-r1"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
configs/Mele_A1000_defconfig +0 -1
index 3424b976772..a407550f6bd 100644
@@ -3,7 +3,6 @@ CONFIG_ARCH_SUNXI=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-a1000"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
-CONFIG_MACPWR="PH15"
 CONFIG_VIDEO_VGA=y
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_AHCI=y
configs/Orangepi_defconfig +0 -1
index b4d5feff309..5c14e327e39 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH26"
 CONFIG_USB2_VBUS_PIN="PH22"
 CONFIG_VIDEO_VGA=y
configs/Orangepi_mini_defconfig +0 -1
index 43197381114..fdacf0cd123 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi-mini"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
configs/bananapi_m1_plus_defconfig +0 -1
index 12ea6a3236a..f398c70ce1a 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/bananapi_m2_plus_h3_defconfig +0 -1
index 2bd5a70a2d0..ab138a43060 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/bananapi_m2_plus_h5_defconfig +0 -1
index 926cf6f5a4d..29200e53585 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h5-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/i12-tvbox_defconfig +0 -1
index d75a7992a82..11971a8a766 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-i12-tvbox"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
-CONFIG_MACPWR="PH21"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/jesurun_q5_defconfig +0 -1
index 2e6b045b549..701d8ecfaa8 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-jesurun-q5"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=312
-CONFIG_MACPWR="PH19"
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/mixtile_loftq_defconfig +0 -0
index 646594b6e07..cdee80b3566 100644

configs/mixtile_loftq_defconfig CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq" · line 7

Quoted 4 lines
configs/mixtile_loftq_defconfig +0 -1
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq"
 CONFIG_SPL=y
 CONFIG_MACH_SUN6I=y
 CONFIG_DRAM_ZQ=251
-CONFIG_MACPWR="PA21"

This board does not have a regulator in its devicetree.

I verified the rest of the boards have an equivalent GPIO-controlled fixed regulator in their devicetrees.

Quoted 187 lines
configs/mixtile_loftq_defconfig +0 -0
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH24"
 CONFIG_USB2_VBUS_PIN=""
configs/nanopi_m1_plus_defconfig +0 -1
index 89065f0411a..a3b82de4de6 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-nanopi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/nanopi_neo_plus2_defconfig +0 -1
index d462b63e944..f7e3efdfe5e 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/nanopi_r1s_h5_defconfig +0 -1
index 5c332ca5261..760dfe37022 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_pc2_defconfig +0 -1
index 356ae7ce476..cf75cf4b351 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
-CONFIG_MACPWR="PD6"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus2e_defconfig +0 -1
index e27b329b0a9..c72adfb3e69 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus2e"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus_defconfig +0 -1
index f4ce4851d7c..c407af38bcc 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/orangepi_win_defconfig +0 -1
index 1e26970230f..b803dcd01ef 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-orangepi-win"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I=y
 CONFIG_RESERVE_ALLWINNER_BOOT0_HEADER=y
-CONFIG_MACPWR="PD14"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/pine_h64_defconfig +0 -1
index 578bd92f6a3..0b482dcea24 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-pine-h64"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H6=y
 CONFIG_SUNXI_DRAM_H6_LPDDR3=y
-CONFIG_MACPWR="PC16"
 CONFIG_MMC0_CD_PIN="PF6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB3_VBUS_PIN="PL5"
configs/zeropi_defconfig +0 -1
index 8365da2c472..7ace1b5cbfd 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-zeropi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 # CONFIG_VIDEO_DE2 is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
drivers/net/sun8i_emac.c +7 -2
index 9cca8fa4e0a..c7087b7302d 100644
@@ -29,6 +29,7 @@
 #include <net.h>
 #include <reset.h>
 #include <wait_bit.h>
+#include <power/regulator.h>
 
 #define MDIO_CMD_MII_BUSY		BIT(0)
 #define MDIO_CMD_MII_WRITE		BIT(1)
@@ -169,9 +170,8 @@ struct emac_eth_dev {
 	struct clk ephy_clk;
 	struct reset_ctl tx_rst;
 	struct reset_ctl ephy_rst;
-#if CONFIG_IS_ENABLED(DM_GPIO)
 	struct gpio_desc reset_gpio;
-#endif
+	struct udevice *phy_reg;
 };
 
 
@@ -738,6 +738,9 @@ static int sun8i_emac_eth_probe(struct udevice *dev)
 
 	sun8i_emac_set_syscon(sun8i_pdata, priv);
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	sun8i_mdio_init(dev->name, dev);
 	priv->bus = miiphy_get_dev_by_name(dev->name);
 
@@ -844,6 +847,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
 		return -EINVAL;
 	}
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);
+
 	pdata->phy_interface = -1;
 	priv->phyaddr = -1;
 	priv->use_internal_phy = false;
drivers/net/sunxi_emac.c +5 -2
index 8625e49dae4..ee8b8a1667d 100644
@@ -17,6 +17,7 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <power/regulator.h>
 
 /* EMAC register  */
 struct emac_regs {
@@ -164,9 +165,8 @@ struct emac_eth_dev {
 	struct mii_dev *bus;
 	struct phy_device *phydev;
 	int link_printed;
-#ifdef CONFIG_DM_ETH
 	uchar rx_buf[EMAC_RX_BUFSIZE];
-#endif
+	struct udevice *phy_reg;
 };
 
 struct emac_rxhdr {
@@ -575,6 +575,9 @@ static int sunxi_emac_eth_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	return sunxi_emac_init_phy(priv, dev);
 }
 

drivers/net/sunxi_emac.c static const struct eth_ops sunxi_emac_eth_ops = { · line 598

Quoted 8 lines
drivers/net/sunxi_emac.c +2 -0
@@ -588,9 +591,12 @@ static const struct eth_ops sunxi_emac_eth_ops = {
 static int sunxi_emac_eth_of_to_plat(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
+	struct emac_eth_dev *priv = dev_get_priv(dev);
 
 	pdata->iobase = dev_read_addr(dev);
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);

For sun4i-emac, the phy-supply property is actually part of the mdio node, not the emac node.

Regards,
Samuel

Quoted 4 lines
drivers/net/sunxi_emac.c +1 -0
+
 	return 0;
 }
 
#7 lore raw

Re: [RFC PATCH 02/17] sunxi: remove CONFIG_MACPWR

On Wed, 14 Dec 2022 03:09:22 -0600
Samuel Holland <[email protected]> wrote:

Hi Samuel,

Quoted 2 lines

Thanks for this cleanup! With the two issues below addressed, it looks good to me.

many thanks for having such a thorough look!

Quoted 8 lines · Andre Przywara
Quoted 7 lines

The CONFIG_MACPWR Kconfig symbol is used to point to a GPIO that enables the power for the Ethernet "MAC" (mostly PHY, really).
In the DT this is described with the phy-supply property in the MAC DT node, pointing to a (GPIO controlled) regulator. Since we need Ethernet only in U-Boot proper, and use a DM driver there, we should use the DT instead of hardcoding this.

Quoted 8 lines
Quoted 5 lines

Add code to the sun8i_emac and sunxi_emac drivers to check the DT for that regulator and enable it, at probe time. Then drop the current code from board.c, which was doing that job before.
This allows us to remove the MACPWR Kconfig definition and the respective values from the defconfigs.

... and we don't care about sun7i-gmac here because there's no U-Boot driver for it, and the Linux driver already uses the devicetree.

If you mean the Gigabit MAC on the A20 (allwinner,sun7i-a20-gmac), that's implemented in drivers/net/designware.c. And this code already parses phy-supply. I think I tried it on my BananaPi, but can double check.

Quoted 76 lines
Quoted 76 lines
---
 arch/arm/mach-sunxi/Kconfig           |  7 -------
 board/sunxi/board.c                   | 10 ----------
 configs/Bananapi_M2_Ultra_defconfig   |  1 -
 configs/Bananapi_defconfig            |  1 -
 configs/Bananapro_defconfig           |  1 -
 configs/Lamobo_R1_defconfig           |  1 -
 configs/Mele_A1000_defconfig          |  1 -
 configs/Orangepi_defconfig            |  1 -
 configs/Orangepi_mini_defconfig       |  1 -
 configs/bananapi_m1_plus_defconfig    |  1 -
 configs/bananapi_m2_plus_h3_defconfig |  1 -
 configs/bananapi_m2_plus_h5_defconfig |  1 -
 configs/i12-tvbox_defconfig           |  1 -
 configs/jesurun_q5_defconfig          |  1 -
 configs/mixtile_loftq_defconfig       |  1 -
 configs/nanopi_m1_plus_defconfig      |  1 -
 configs/nanopi_neo_plus2_defconfig    |  1 -
 configs/nanopi_r1s_h5_defconfig       |  1 -
 configs/orangepi_pc2_defconfig        |  1 -
 configs/orangepi_plus2e_defconfig     |  1 -
 configs/orangepi_plus_defconfig       |  1 -
 configs/orangepi_win_defconfig        |  1 -
 configs/pine_h64_defconfig            |  1 -
 configs/zeropi_defconfig              |  1 -
 drivers/net/sun8i_emac.c              |  9 +++++++--
 drivers/net/sunxi_emac.c              | 10 ++++++++--
 26 files changed, 15 insertions(+), 43 deletions(-)
arch/arm/mach-sunxi/Kconfig +0 -7
index 5f95fe72d08..6220175d612 100644
@@ -645,13 +645,6 @@ config OLD_SUNXI_KERNEL_COMPAT
 	Set this to enable various workarounds for old kernels, this results in
 	sub-optimal settings for newer kernels, only enable if needed.
 
-config MACPWR
-	string "MAC power pin"
-	default ""
-	help
-	  Set the pin used to power the MAC. This takes a string in the format
-	  understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
-
 config MMC0_CD_PIN
 	string "Card detect pin for mmc0"
 	default "PF6" if MACH_SUN8I_A83T || MACH_SUNXI_H3_H5 || MACH_SUN50I
board/sunxi/board.c +0 -10
index ec35a7f06bd..3077cc71ebd 100644
@@ -228,15 +228,6 @@ int board_init(void)
 	if (ret)
 		return ret;
 
-	/* strcmp() would look better, but doesn't get optimised away. */
-	if (CONFIG_MACPWR[0]) {
-		macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
-		if (macpwr_pin >= 0) {
-			gpio_request(macpwr_pin, "macpwr");
-			gpio_direction_output(macpwr_pin, 1);
-		}
-	}
-
 #if CONFIG_IS_ENABLED(DM_I2C)
 	/*
 	 * Temporary workaround for enabling I2C clocks until proper sunxi DM
@@ -244,7 +235,6 @@ int board_init(void)
 	 */
 	i2c_init_board();
 #endif
-
 	eth_init_board();
 
Quoted 13 lines

configs/Bananapi_M2_Ultra_defconfig CONFIG_DEFAULT_DEVICE_TREE="sun8i-r40-bananapi-m2-ultra" · line 7

Quoted 10 lines
board/sunxi/board.c +0 -0
 	return 0;
configs/Bananapi_M2_Ultra_defconfig +0 -1
index 0bd163afdd7..1c4b90ab9d2 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r40-bananapi-m2-ultra"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_R40=y
 CONFIG_DRAM_CLK=576
-CONFIG_MACPWR="PA17"  

This GPIO is actually the PHY reset line, not its power supply. Since that line has a pull up, I don't think this was necessary to begin with.

Ha, good find. Indeed the schematic confirms that. And the BPi M2 Berry uses the same connection, but doesn't mention PA17 at all (neither in the defconfig nor in the DT). I don't have a M2U, but will play around with my M2 Berry, to simulate that.

Quoted 138 lines
Quoted 138 lines
configs/Bananapi_M2_Ultra_defconfig +0 -0
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH23"
configs/Bananapi_defconfig +0 -1
index 2814d77c187..2a590e141d9 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/Bananapro_defconfig +0 -1
index 11375991c81..4b56195d4f2 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapro"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH0"
 CONFIG_USB2_VBUS_PIN="PH1"
 CONFIG_VIDEO_COMPOSITE=y
configs/Lamobo_R1_defconfig +0 -1
index d51601ff10f..fc63a7fbd46 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-lamobo-r1"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_GMAC_TX_DELAY=4
 CONFIG_AHCI=y
configs/Mele_A1000_defconfig +0 -1
index 3424b976772..a407550f6bd 100644
@@ -3,7 +3,6 @@ CONFIG_ARCH_SUNXI=y
 CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-a1000"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
-CONFIG_MACPWR="PH15"
 CONFIG_VIDEO_VGA=y
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_AHCI=y
configs/Orangepi_defconfig +0 -1
index b4d5feff309..5c14e327e39 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_USB1_VBUS_PIN="PH26"
 CONFIG_USB2_VBUS_PIN="PH22"
 CONFIG_VIDEO_VGA=y
configs/Orangepi_mini_defconfig +0 -1
index 43197381114..fdacf0cd123 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-orangepi-mini"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_MMC0_CD_PIN="PH10"
 CONFIG_MMC3_CD_PIN="PH11"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=3
configs/bananapi_m1_plus_defconfig +0 -1
index 12ea6a3236a..f398c70ce1a 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-bananapi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=432
-CONFIG_MACPWR="PH23"
 CONFIG_VIDEO_COMPOSITE=y
 CONFIG_GMAC_TX_DELAY=3
 CONFIG_AHCI=y
configs/bananapi_m2_plus_h3_defconfig +0 -1
index 2bd5a70a2d0..ab138a43060 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/bananapi_m2_plus_h5_defconfig +0 -1
index 926cf6f5a4d..29200e53585 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h5-bananapi-m2-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/i12-tvbox_defconfig +0 -1
index d75a7992a82..11971a8a766 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-i12-tvbox"
 CONFIG_SPL=y
 CONFIG_MACH_SUN7I=y
 CONFIG_DRAM_CLK=384
-CONFIG_MACPWR="PH21"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/jesurun_q5_defconfig +0 -1
index 2e6b045b549..701d8ecfaa8 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun4i-a10-jesurun-q5"
 CONFIG_SPL=y
 CONFIG_MACH_SUN4I=y
 CONFIG_DRAM_CLK=312
-CONFIG_MACPWR="PH19"
 CONFIG_USB0_VBUS_PIN="PB9"
 CONFIG_VIDEO_COMPOSITE=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/mixtile_loftq_defconfig +0 -1
index 646594b6e07..cdee80b3566 100644
--- a/configs/mixtile_loftq_defconfig
Quoted 8 lines

configs/mixtile_loftq_defconfig CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq" · line 7

Quoted 6 lines

+++ b/configs/mixtile_loftq_defconfig

configs/mixtile_loftq_defconfig +0 -1
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun6i-a31-mixtile-loftq"
 CONFIG_SPL=y
 CONFIG_MACH_SUN6I=y
 CONFIG_DRAM_ZQ=251
-CONFIG_MACPWR="PA21"  

This board does not have a regulator in its devicetree.

Yeah, that's an odd one, as the DT only exists in the U-Boot tree. So we could just add it. I guess given the age and "support status" of this board no one would care anyways ;-)

Quoted 2 lines

I verified the rest of the boards have an equivalent GPIO-controlled fixed regulator in their devicetrees.

Oh, many thanks!

Quoted 192 lines
Quoted 192 lines
configs/mixtile_loftq_defconfig +0 -0
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PH24"
 CONFIG_USB2_VBUS_PIN=""
configs/nanopi_m1_plus_defconfig +0 -1
index 89065f0411a..a3b82de4de6 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-nanopi-m1-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/nanopi_neo_plus2_defconfig +0 -1
index d462b63e944..f7e3efdfe5e 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/nanopi_r1s_h5_defconfig +0 -1
index 5c332ca5261..760dfe37022 100644
@@ -6,7 +6,6 @@ CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_pc2_defconfig +0 -1
index 356ae7ce476..cf75cf4b351 100644
@@ -5,7 +5,6 @@ CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H5=y
 CONFIG_DRAM_CLK=672
 CONFIG_DRAM_ZQ=3881977
-CONFIG_MACPWR="PD6"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus2e_defconfig +0 -1
index e27b329b0a9..c72adfb3e69 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus2e"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/orangepi_plus_defconfig +0 -1
index f4ce4851d7c..c407af38bcc 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=672
-CONFIG_MACPWR="PD6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB1_VBUS_PIN="PG13"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
configs/orangepi_win_defconfig +0 -1
index 1e26970230f..b803dcd01ef 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-orangepi-win"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I=y
 CONFIG_RESERVE_ALLWINNER_BOOT0_HEADER=y
-CONFIG_MACPWR="PD14"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
configs/pine_h64_defconfig +0 -1
index 578bd92f6a3..0b482dcea24 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun50i-h6-pine-h64"
 CONFIG_SPL=y
 CONFIG_MACH_SUN50I_H6=y
 CONFIG_SUNXI_DRAM_H6_LPDDR3=y
-CONFIG_MACPWR="PC16"
 CONFIG_MMC0_CD_PIN="PF6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
 CONFIG_USB3_VBUS_PIN="PL5"
configs/zeropi_defconfig +0 -1
index 8365da2c472..7ace1b5cbfd 100644
@@ -4,7 +4,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-zeropi"
 CONFIG_SPL=y
 CONFIG_MACH_SUN8I_H3=y
 CONFIG_DRAM_CLK=408
-CONFIG_MACPWR="PD6"
 # CONFIG_VIDEO_DE2 is not set
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SYS_MONITOR_LEN=786432
drivers/net/sun8i_emac.c +7 -2
index 9cca8fa4e0a..c7087b7302d 100644
@@ -29,6 +29,7 @@
 #include <net.h>
 #include <reset.h>
 #include <wait_bit.h>
+#include <power/regulator.h>
 
 #define MDIO_CMD_MII_BUSY		BIT(0)
 #define MDIO_CMD_MII_WRITE		BIT(1)
@@ -169,9 +170,8 @@ struct emac_eth_dev {
 	struct clk ephy_clk;
 	struct reset_ctl tx_rst;
 	struct reset_ctl ephy_rst;
-#if CONFIG_IS_ENABLED(DM_GPIO)
 	struct gpio_desc reset_gpio;
-#endif
+	struct udevice *phy_reg;
 };
 
 
@@ -738,6 +738,9 @@ static int sun8i_emac_eth_probe(struct udevice *dev)
 
 	sun8i_emac_set_syscon(sun8i_pdata, priv);
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	sun8i_mdio_init(dev->name, dev);
 	priv->bus = miiphy_get_dev_by_name(dev->name);
 
@@ -844,6 +847,8 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
 		return -EINVAL;
 	}
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);
+
 	pdata->phy_interface = -1;
 	priv->phyaddr = -1;
 	priv->use_internal_phy = false;
drivers/net/sunxi_emac.c +6 -2
index 8625e49dae4..ee8b8a1667d 100644
@@ -17,6 +17,7 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
+#include <power/regulator.h>
 
 /* EMAC register  */
 struct emac_regs {
@@ -164,9 +165,8 @@ struct emac_eth_dev {
 	struct mii_dev *bus;
 	struct phy_device *phydev;
 	int link_printed;
-#ifdef CONFIG_DM_ETH
 	uchar rx_buf[EMAC_RX_BUFSIZE];
-#endif
+	struct udevice *phy_reg;
 };
 
 struct emac_rxhdr {
@@ -575,6 +575,9 @@ static int sunxi_emac_eth_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
+	if (priv->phy_reg)
+		regulator_set_enable(priv->phy_reg, true);
+
 	return sunxi_emac_init_phy(priv, dev);
 }
 
@@ -588,9 +591,12 @@ static const struct eth_ops sunxi_emac_eth_ops = {
 static int sunxi_emac_eth_of_to_plat(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
+	struct emac_eth_dev *priv = dev_get_priv(dev);
 
Quoted 6 lines

drivers/net/sunxi_emac.c static const struct eth_ops sunxi_emac_eth_ops = { · line 598

Quoted 3 lines
drivers/net/sunxi_emac.c +1 -0
 	pdata->iobase = dev_read_addr(dev);
 
+	device_get_supply_regulator(dev, "phy-supply", &priv->phy_reg);  

For sun4i-emac, the phy-supply property is actually part of the mdio node, not the emac node.

Huh, right. As far as I can tell, this only affects two boards, Mele_A1000 and jesurun_q5, which I don't have.
So can we follow the link to the PHY node, then go to its parent, which should be the MDIO node? And pick the regulator from there?

Cheers,
Andre

Quoted 8 lines

Regards,
Samuel

Quoted 4 lines
drivers/net/sunxi_emac.c +1 -0
+
 	return 0;
 }
 
#8 lore raw

RFC PATCH 3/17 pinctrl: sunxi: remove struct sunxi_gpio

In reply to Andre Przywara

So far every Allwinner SoC used the same basic pincontroller/GPIO register frame, and just differed by the number of implemented banks and pins, plus some special functionality from time to time. However the D1 and successors use a slightly different pinctrl register layout. Use that opportunity to drop "struct sunxi_gpio", that described that MMIO frame in a C struct. That approach is somewhat frowned upon in the Linux world and rarely used there, though still popular with U-Boot.

Switching from a C struct to a "base address plus offset" approach allows to switch between the two models more dynamically, without reverting to preprocessor macros and #ifdef's.

Model the pinctrl MMIO register frame in the usual "base address + offset" way, and replace a hard-to-parse CPP macro with a more readable static function.
All the users get converted over. There are no functional changes at this point, it just prepares the stages for the D1 and friends.

---
 arch/arm/include/asm/arch-sunxi/gpio.h | 63 +++++++++++---------------
 arch/arm/mach-sunxi/pinmux.c           | 51 +++++++++++----------
 drivers/gpio/sunxi_gpio.c              | 15 +++---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c  | 14 +++---
 4 files changed, 68 insertions(+), 75 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +26 -37
index 437e86479ce..8333810a69f 100644
@@ -28,13 +28,6 @@
 #define SUNXI_GPIO_H	7
 #define SUNXI_GPIO_I	8
 
-/*
- * This defines the number of GPIO banks for the _main_ GPIO controller.
- * You should fix up the padding in struct sunxi_gpio_reg below if you
- * change this.
- */
-#define SUNXI_GPIO_BANKS 9
-
 /*
  * sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO)
  * at a different register offset.
@@ -52,46 +45,42 @@
 #define SUNXI_GPIO_M	12
 #define SUNXI_GPIO_N	13
 
-struct sunxi_gpio {
-	u32 cfg[4];
-	u32 dat;
-	u32 drv[2];
-	u32 pull[2];
-};
-
-/* gpio interrupt control */
-struct sunxi_gpio_int {
-	u32 cfg[3];
-	u32 ctl;
-	u32 sta;
-	u32 deb;		/* interrupt debounce */
-};
-
-struct sunxi_gpio_reg {
-	struct sunxi_gpio gpio_bank[SUNXI_GPIO_BANKS];
-	u8 res[0xbc];
-	struct sunxi_gpio_int gpio_int;
-};
-
 #define SUN50I_H6_GPIO_POW_MOD_SEL	0x340
 #define SUN50I_H6_GPIO_POW_MOD_VAL	0x348
 
-#define BANK_TO_GPIO(bank)	(((bank) < SUNXI_GPIO_L) ? \
-	&((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank] : \
-	&((struct sunxi_gpio_reg *)SUNXI_R_PIO_BASE)->gpio_bank[(bank) - SUNXI_GPIO_L])
-
 #define GPIO_BANK(pin)		((pin) >> 5)
 #define GPIO_NUM(pin)		((pin) & 0x1f)
 
+#define GPIO_CFG_REG_OFFSET	0x00
 #define GPIO_CFG_INDEX(pin)	(((pin) & 0x1f) >> 3)
 #define GPIO_CFG_OFFSET(pin)	((((pin) & 0x1f) & 0x7) << 2)
 
+#define GPIO_DAT_REG_OFFSET	0x10
+
+#define GPIO_DRV_REG_OFFSET	0x14
 #define GPIO_DRV_INDEX(pin)	(((pin) & 0x1f) >> 4)
 #define GPIO_DRV_OFFSET(pin)	((((pin) & 0x1f) & 0xf) << 1)
 
+#define GPIO_PULL_REG_OFFSET	0x1c
 #define GPIO_PULL_INDEX(pin)	(((pin) & 0x1f) >> 4)
 #define GPIO_PULL_OFFSET(pin)	((((pin) & 0x1f) & 0xf) << 1)
 
+#define SUNXI_PINCTRL_BANK_SIZE 0x24
+
+static inline void* BANK_TO_GPIO(int bank)
+{
+	void *pio_base;
+
+	if (bank < SUNXI_GPIO_L) {
+		pio_base = (void *)(uintptr_t)SUNXI_PIO_BASE;
+	} else {
+		pio_base = (void *)(uintptr_t)SUNXI_R_PIO_BASE;
+		bank -= SUNXI_GPIO_L;
+	}
+
+	return pio_base + bank * SUNXI_PINCTRL_BANK_SIZE;
+}
+
 /* GPIO bank sizes */
 #define SUNXI_GPIOS_PER_BANK	32
 
@@ -214,18 +203,18 @@ enum sunxi_gpio_number {
 #define SUNXI_GPIO_AXP0_GPIO_COUNT	6
 
 struct sunxi_gpio_plat {
-	struct sunxi_gpio	*regs;
+	void			*regs;
 	char			bank_name[3];
 };
 
-void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
+void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val);
 void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
-int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset);
+int sunxi_gpio_get_cfgbank(void *bank_base, int pin_offset);
 int sunxi_gpio_get_cfgpin(u32 pin);
 void sunxi_gpio_set_drv(u32 pin, u32 val);
-void sunxi_gpio_set_drv_bank(struct sunxi_gpio *pio, u32 bank_offset, u32 val);
+void sunxi_gpio_set_drv_bank(void *bank_base, u32 pin_offset, u32 val);
 void sunxi_gpio_set_pull(u32 pin, u32 val);
-void sunxi_gpio_set_pull_bank(struct sunxi_gpio *pio, int bank_offset, u32 val);
+void sunxi_gpio_set_pull_bank(void *bank_base, int pin_offset, u32 val);
 int sunxi_name_to_gpio(const char *name);
 
 #if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
arch/arm/mach-sunxi/pinmux.c +27 -24

95 lines not on this page · raw message

drivers/gpio/sunxi_gpio.c +8 -7
index 1e85db179a6..1bf691a204a 100644
@@ -24,15 +24,15 @@ static int sunxi_gpio_output(u32 pin, u32 val)
 	u32 dat;
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
-	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
+	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(&pio->dat);
+	dat = readl(pio + 0x10);
 	if (val)
 		dat |= 0x1 << num;
 	else
 		dat &= ~(0x1 << num);
 
-	writel(dat, &pio->dat);
+	writel(dat, pio + 0x10);
 
 	return 0;
 }
@@ -42,9 +42,9 @@ static int sunxi_gpio_input(u32 pin)
 	u32 dat;
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
-	struct sunxi_gpio *pio = BANK_TO_GPIO(bank);
+	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(&pio->dat);
+	dat = readl(pio + 0x10);
 	dat >>= num;
 
 	return dat & 0x1;
@@ -138,7 +138,7 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)
 	u32 num = GPIO_NUM(offset);
 	unsigned dat;
 
-	dat = readl(&plat->regs->dat);
+	dat = readl(plat->regs + GPIO_DAT_REG_OFFSET);
 	dat >>= num;
 
 	return dat & 0x1;
@@ -181,7 +181,8 @@ static int sunxi_gpio_set_flags(struct udevice *dev, unsigned int offset,
 		u32 value = !!(flags & GPIOD_IS_OUT_ACTIVE);
 		u32 num = GPIO_NUM(offset);
 
-		clrsetbits_le32(&plat->regs->dat, 1 << num, value << num);
+		clrsetbits_le32(plat->regs + GPIO_DAT_REG_OFFSET,
+				1 << num, value << num);
 		sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT);
 	} else if (flags & GPIOD_IS_IN) {
 		u32 pull = 0;
drivers/pinctrl/sunxi/pinctrl-sunxi.c +7 -7
index 061104be056..5ab3951ab52 100644
@@ -35,7 +35,7 @@ struct sunxi_pinctrl_desc {
 };
 
 struct sunxi_pinctrl_plat {
-	struct sunxi_gpio __iomem *base;
+	void __iomem *base;
 };
 
 static int sunxi_pinctrl_get_pins_count(struct udevice *dev)
@@ -86,8 +86,8 @@ static int sunxi_pinctrl_pinmux_set(struct udevice *dev, uint pin_selector,
 	      sunxi_pinctrl_get_function_name(dev, func_selector),
 	      desc->functions[func_selector].mux);
 
-	sunxi_gpio_set_cfgbank(plat->base + bank, pin,
-			       desc->functions[func_selector].mux);
+	sunxi_gpio_set_cfgbank(plat->base + bank * SUNXI_PINCTRL_BANK_SIZE,
+			       pin, desc->functions[func_selector].mux);
 
 	return 0;
 }
@@ -102,7 +102,7 @@ static const struct pinconf_param sunxi_pinctrl_pinconf_params[] = {
 static int sunxi_pinctrl_pinconf_set_pull(struct sunxi_pinctrl_plat *plat,
 					  uint bank, uint pin, uint bias)
 {
-	struct sunxi_gpio *regs = &plat->base[bank];
+	void *regs = plat->base + bank * SUNXI_PINCTRL_BANK_SIZE;
 
 	sunxi_gpio_set_pull_bank(regs, pin, bias);
 
@@ -112,7 +112,7 @@ static int sunxi_pinctrl_pinconf_set_pull(struct sunxi_pinctrl_plat *plat,
 static int sunxi_pinctrl_pinconf_set_drive(struct sunxi_pinctrl_plat *plat,
 					   uint bank, uint pin, uint drive)
 {
-	struct sunxi_gpio *regs = &plat->base[bank];
+	void *regs = plat->base + bank * SUNXI_PINCTRL_BANK_SIZE;
 
 	if (drive < 10 || drive > 40)
 		return -EINVAL;
@@ -148,7 +148,7 @@ static int sunxi_pinctrl_get_pin_muxing(struct udevice *dev, uint pin_selector,
 	struct sunxi_pinctrl_plat *plat = dev_get_plat(dev);
 	int bank = pin_selector / SUNXI_GPIOS_PER_BANK;
 	int pin	 = pin_selector % SUNXI_GPIOS_PER_BANK;
-	int mux  = sunxi_gpio_get_cfgbank(plat->base + bank, pin);
+	int mux  = sunxi_gpio_get_cfgbank(plat->base + bank * SUNXI_PINCTRL_BANK_SIZE, pin);
 
 	switch (mux) {
 	case SUNXI_GPIO_INPUT:
@@ -206,7 +206,7 @@ static int sunxi_pinctrl_bind(struct udevice *dev)
 		if (!gpio_plat)
 			return -ENOMEM;
 
-		gpio_plat->regs = plat->base + i;
+		gpio_plat->regs = plat->base + i * SUNXI_PINCTRL_BANK_SIZE;
 		gpio_plat->bank_name[0] = 'P';
 		gpio_plat->bank_name[1] = 'A' + desc->first_bank + i;
 		gpio_plat->bank_name[2] = '\0';
Signature · 1 line
2.35.5
#9 lore raw

RFC PATCH 4/17 pinctrl: sunxi: add GPIO in/out wrappers

In reply to Andre Przywara

So far we were open-coding the pincontroller's GPIO output/input access in each function using that.

Provide two functions that wrap that nicely, so users don't need to know about the internals, and we can abstract the new D1 pinctrl more easily.

---
 arch/arm/include/asm/arch-sunxi/gpio.h |  2 ++
 arch/arm/mach-sunxi/pinmux.c           | 10 ++++++++++
 drivers/gpio/sunxi_gpio.c              | 26 +++++---------------------
 3 files changed, 17 insertions(+), 21 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +2 -0
index 8333810a69f..42ca03d8c18 100644
@@ -211,6 +211,8 @@ void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val);
 void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
 int sunxi_gpio_get_cfgbank(void *bank_base, int pin_offset);
 int sunxi_gpio_get_cfgpin(u32 pin);
+void sunxi_gpio_set_output_bank(void *bank_base, u32 clear_mask, u32 set_mask);
+u32 sunxi_gpio_get_output_bank(void *bank_base);
 void sunxi_gpio_set_drv(u32 pin, u32 val);
 void sunxi_gpio_set_drv_bank(void *bank_base, u32 pin_offset, u32 val);
 void sunxi_gpio_set_pull(u32 pin, u32 val);
arch/arm/mach-sunxi/pinmux.c +10 -0
index b650f6b1aea..91acbf9269f 100644
@@ -46,6 +46,16 @@ int sunxi_gpio_get_cfgpin(u32 pin)
 	return sunxi_gpio_get_cfgbank(bank_base, pin % 32);
 }
 
+void sunxi_gpio_set_output_bank(void *bank_base, u32 clear_mask, u32 set_mask)
+{
+	clrsetbits_le32(bank_base + GPIO_DAT_REG_OFFSET, clear_mask, set_mask);
+}
+
+u32 sunxi_gpio_get_output_bank(void *bank_base)
+{
+	return readl(bank_base + GPIO_DAT_REG_OFFSET);
+}
+
 void sunxi_gpio_set_drv(u32 pin, u32 val)
 {
 	u32 bank = GPIO_BANK(pin);
drivers/gpio/sunxi_gpio.c +5 -21
index 1bf691a204a..767996c10fc 100644
@@ -21,33 +21,22 @@
 #if !CONFIG_IS_ENABLED(DM_GPIO)
 static int sunxi_gpio_output(u32 pin, u32 val)
 {
-	u32 dat;
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
 	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(pio + 0x10);
-	if (val)
-		dat |= 0x1 << num;
-	else
-		dat &= ~(0x1 << num);
-
-	writel(dat, pio + 0x10);
-
+	sunxi_gpio_set_output_bank(pio, val ? 0 : 1U << num,
+					val ? 1U << num : 0);
 	return 0;
 }
 
 static int sunxi_gpio_input(u32 pin)
 {
-	u32 dat;
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
 	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(pio + 0x10);
-	dat >>= num;
-
-	return dat & 0x1;
+	return (sunxi_gpio_get_output_bank(pio) >> num) & 0x1;
 }
 
 int gpio_request(unsigned gpio, const char *label)
@@ -136,12 +125,8 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)
 {
 	struct sunxi_gpio_plat *plat = dev_get_plat(dev);
 	u32 num = GPIO_NUM(offset);
-	unsigned dat;
-
-	dat = readl(plat->regs + GPIO_DAT_REG_OFFSET);
-	dat >>= num;
 
-	return dat & 0x1;
+	return (sunxi_gpio_get_output_bank(plat->regs) >> num) & 0x1;
 }
 
 static int sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
@@ -181,8 +166,7 @@ static int sunxi_gpio_set_flags(struct udevice *dev, unsigned int offset,
 		u32 value = !!(flags & GPIOD_IS_OUT_ACTIVE);
 		u32 num = GPIO_NUM(offset);
 
-		clrsetbits_le32(plat->regs + GPIO_DAT_REG_OFFSET,
-				1 << num, value << num);
+		sunxi_gpio_set_output_bank(plat->regs, 1U << num, value << num);
 		sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT);
 	} else if (flags & GPIOD_IS_IN) {
 		u32 pull = 0;
Signature · 1 line
2.35.5
maintainer
#10 lore raw

Re: [RFC PATCH 04/17] pinctrl: sunxi: add GPIO in/out wrappers

Quoted 76 lines · Andre Przywara

So far we were open-coding the pincontroller's GPIO output/input access in each function using that.

Provide two functions that wrap that nicely, so users don't need to know about the internals, and we can abstract the new D1 pinctrl more easily.

---
 arch/arm/include/asm/arch-sunxi/gpio.h |  2 ++
 arch/arm/mach-sunxi/pinmux.c           | 10 ++++++++++
 drivers/gpio/sunxi_gpio.c              | 26 +++++---------------------
 3 files changed, 17 insertions(+), 21 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +2 -0
index 8333810a69f..42ca03d8c18 100644
@@ -211,6 +211,8 @@ void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val);
 void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
 int sunxi_gpio_get_cfgbank(void *bank_base, int pin_offset);
 int sunxi_gpio_get_cfgpin(u32 pin);
+void sunxi_gpio_set_output_bank(void *bank_base, u32 clear_mask, u32 set_mask);
+u32 sunxi_gpio_get_output_bank(void *bank_base);
 void sunxi_gpio_set_drv(u32 pin, u32 val);
 void sunxi_gpio_set_drv_bank(void *bank_base, u32 pin_offset, u32 val);
 void sunxi_gpio_set_pull(u32 pin, u32 val);
arch/arm/mach-sunxi/pinmux.c +10 -0
index b650f6b1aea..91acbf9269f 100644
@@ -46,6 +46,16 @@ int sunxi_gpio_get_cfgpin(u32 pin)
 	return sunxi_gpio_get_cfgbank(bank_base, pin % 32);
 }
 
+void sunxi_gpio_set_output_bank(void *bank_base, u32 clear_mask, u32 set_mask)
+{
+	clrsetbits_le32(bank_base + GPIO_DAT_REG_OFFSET, clear_mask, set_mask);
+}
+
+u32 sunxi_gpio_get_output_bank(void *bank_base)
+{
+	return readl(bank_base + GPIO_DAT_REG_OFFSET);
+}
+
 void sunxi_gpio_set_drv(u32 pin, u32 val)
 {
 	u32 bank = GPIO_BANK(pin);
drivers/gpio/sunxi_gpio.c +2 -10
index 1bf691a204a..767996c10fc 100644
@@ -21,33 +21,22 @@
 #if !CONFIG_IS_ENABLED(DM_GPIO)
 static int sunxi_gpio_output(u32 pin, u32 val)
 {
-	u32 dat;
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
 	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(pio + 0x10);
-	if (val)
-		dat |= 0x1 << num;
-	else
-		dat &= ~(0x1 << num);
-
-	writel(dat, pio + 0x10);
-
+	sunxi_gpio_set_output_bank(pio, val ? 0 : 1U << num,
+					val ? 1U << num : 0);
 	return 0;
 }
 
 static int sunxi_gpio_input(u32 pin)
 {
-	u32 dat;

drivers/gpio/sunxi_gpio.c line 40

Quoted 10 lines
drivers/gpio/sunxi_gpio.c +1 -4
 	u32 bank = GPIO_BANK(pin);
 	u32 num = GPIO_NUM(pin);
 	void *pio = BANK_TO_GPIO(bank);
 
-	dat = readl(pio + 0x10);
-	dat >>= num;
-
-	return dat & 0x1;
+	return (sunxi_gpio_get_output_bank(pio) >> num) & 0x1;
 }

I would suggest putting this change before patch 3. And I would suggest following the existing pattern of functions, with an inner one taking (bank pointer, pin offset, value), and a wrapper calling BANK_TO_GPIO. This would consolidate the shifting/masking as well.

If you move these two functions to pinmux.c, then all of the BANK_TO_GPIO callers are in that file, and you can move BANK_TO_GPIO to pinmux.c as well when you remove the struct and touch all of the call sites anyway.

Regards,
Samuel

Quoted 26 lines
drivers/gpio/sunxi_gpio.c +2 -7
 int gpio_request(unsigned gpio, const char *label)
@@ -136,12 +125,8 @@ static int sunxi_gpio_get_value(struct udevice *dev, unsigned offset)
 {
 	struct sunxi_gpio_plat *plat = dev_get_plat(dev);
 	u32 num = GPIO_NUM(offset);
-	unsigned dat;
-
-	dat = readl(plat->regs + GPIO_DAT_REG_OFFSET);
-	dat >>= num;
 
-	return dat & 0x1;
+	return (sunxi_gpio_get_output_bank(plat->regs) >> num) & 0x1;
 }
 
 static int sunxi_gpio_get_function(struct udevice *dev, unsigned offset)
@@ -181,8 +166,7 @@ static int sunxi_gpio_set_flags(struct udevice *dev, unsigned int offset,
 		u32 value = !!(flags & GPIOD_IS_OUT_ACTIVE);
 		u32 num = GPIO_NUM(offset);
 
-		clrsetbits_le32(plat->regs + GPIO_DAT_REG_OFFSET,
-				1 << num, value << num);
+		sunxi_gpio_set_output_bank(plat->regs, 1U << num, value << num);
 		sunxi_gpio_set_cfgbank(plat->regs, offset, SUNXI_GPIO_OUTPUT);
 	} else if (flags & GPIOD_IS_IN) {
 		u32 pull = 0;
#11 lore raw

RFC PATCH 5/17 pinctrl: sunxi: move pinctrl code and remove GPIO_EXTRA_HEADER

In reply to Andre Przywara

U-Boot's generic GPIO_EXTRA_HEADER is a convenience symbol to allow code to more easily include platform specific GPIO headers. This should not be needed in a DM world anymore, since the generic GPIO framework handles that nicely.
For Allwinner boards we still need to deal with non-DM GPIO in the SPL, but this should become the exception, not the rule.

Make this more obvious by removing the definition of GPIO_EXTRA_HEADER, and just force every legacy user of platform specific GPIO to include the new sunxi_gpio.h header explicitly. Everyone doing so should feel ashamed and should find a way to avoid it from now on.
This also moves and renames the existing sunxi-specific low level pinctrl routines from arch/arm/mach-sunxi into board/sunxi, and the gpio.h header to the generic include/ directory, so the common code can be shared outside of arch/arm.

---
 arch/arm/Kconfig                                             | 1 -
 arch/arm/mach-sunxi/Makefile                                 | 1 -
 arch/arm/mach-sunxi/board.c                                  | 1 +
 arch/arm/mach-sunxi/dram_suniv.c                             | 2 +-
 arch/arm/mach-sunxi/spl_spi_sunxi.c                          | 1 +
 board/sunxi/Makefile                                         | 1 +
 board/sunxi/board.c                                          | 1 +
 board/sunxi/chip.c                                           | 2 +-
 arch/arm/mach-sunxi/pinmux.c => board/sunxi/pinctrl.c        | 5 ++++-
 drivers/gpio/axp_gpio.c                                      | 1 +
 drivers/gpio/sunxi_gpio.c                                    | 1 +
 drivers/i2c/sun6i_p2wi.c                                     | 2 +-
 drivers/i2c/sun8i_rsb.c                                      | 2 +-
 drivers/mmc/sunxi_mmc.c                                      | 1 +
 drivers/pinctrl/sunxi/pinctrl-sunxi.c                        | 1 +
 drivers/video/hitachi_tx18d42vm_lcd.c                        | 1 +
 drivers/video/ssd2828.c                                      | 1 -
 drivers/video/sunxi/sunxi_display.c                          | 1 +
 drivers/video/sunxi/sunxi_lcd.c                              | 1 +
 .../include/asm/arch-sunxi/gpio.h => include/sunxi_gpio.h    | 0
 20 files changed, 19 insertions(+), 8 deletions(-)
 rename arch/arm/mach-sunxi/pinmux.c => board/sunxi/pinctrl.c (93%)
 rename arch/arm/include/asm/arch-sunxi/gpio.h => include/sunxi_gpio.h (100%)
arch/arm/Kconfig +0 -1
index 3623520b353..c19b2c49359 100644
@@ -1152,7 +1152,6 @@ config ARCH_SUNXI
 	select DM_REGULATOR_FIXED
 	select DM_SCSI if SCSI
 	select DM_SERIAL
-	select GPIO_EXTRA_HEADER
 	select OF_BOARD_SETUP
 	select OF_CONTROL
 	select OF_SEPARATE
arch/arm/mach-sunxi/Makefile +0 -1
index 58f807cb82d..671211e9322 100644
@@ -10,7 +10,6 @@ obj-y	+= board.o
 obj-y	+= clock.o
 obj-y	+= cpu_info.o
 obj-y	+= dram_helpers.o
-obj-y	+= pinmux.o
 obj-$(CONFIG_SUN6I_PRCM)	+= prcm.o
 obj-$(CONFIG_AXP_PMIC_BUS)	+= pmic_bus.o
 obj-$(CONFIG_MACH_SUNIV)	+= clock_sun6i.o
arch/arm/mach-sunxi/board.c +1 -0
index 86233637bfc..b6ffbff883c 100644
@@ -17,6 +17,7 @@
 #include <i2c.h>
 #include <serial.h>
 #include <spl.h>
+#include <sunxi_gpio.h>
 #include <asm/cache.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
arch/arm/mach-sunxi/dram_suniv.c +1 -1
index 56c2d557ff1..fcc8dad2a2f 100644
@@ -13,10 +13,10 @@
 #include <asm/io.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/dram.h>
-#include <asm/arch/gpio.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <hang.h>
+#include <sunxi_gpio.h>
 
 #define SDR_T_CAS			(0x2)
 #define SDR_T_RAS			(0x8)
arch/arm/mach-sunxi/spl_spi_sunxi.c +1 -0
index 81159cfee61..c2410dd7bb1 100644
@@ -13,6 +13,7 @@
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/libfdt.h>
+#include <sunxi_gpio.h>
 
 #ifdef CONFIG_SPL_OS_BOOT
 #error CONFIG_SPL_OS_BOOT is not supported yet
board/sunxi/Makefile +1 -0
index d96b7897b6c..7763b032c80 100644
@@ -7,6 +7,7 @@
 # (C) Copyright 2000-2003
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 obj-y	+= board.o
+obj-y	+= pinctrl.o
 obj-$(CONFIG_SUN7I_GMAC)	+= gmac.o
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
board/sunxi/board.c +1 -0
index 3077cc71ebd..ef24413de4c 100644
@@ -38,6 +38,7 @@
 #include <asm/armv7.h>
 #endif
 #include <asm/gpio.h>
+#include <sunxi_gpio.h>
 #include <asm/io.h>
 #include <u-boot/crc.h>
 #include <env_internal.h>
board/sunxi/chip.c +1 -1
index cde04bebe96..eeee6319e79 100644
@@ -12,7 +12,7 @@
 #include <w1-eeprom.h>
 #include <dm/device-internal.h>
 
-#include <asm/arch/gpio.h>
+#include <sunxi_gpio.h>
 
 #include <extension_board.h>
 
board/sunxi/pinctrl.c renamed from arch/arm/mach-sunxi/pinmux.c +4 -1
similarity index 93%
rename from arch/arm/mach-sunxi/pinmux.c
rename to board/sunxi/pinctrl.c
index 91acbf9269f..aac37f639b8 100644
@@ -3,11 +3,14 @@
  * (C) Copyright 2007-2011
  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  * Tom Cubie <[email protected]>
+ *
+ * Low level GPIO/pin controller access functions, to be shared by non-DM
+ * SPL code and the DM pinctrl/GPIO drivers.
  */
 
 #include <common.h>
 #include <asm/io.h>
-#include <asm/arch/gpio.h>
+#include <sunxi_gpio.h>
 
 void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val)
 {
drivers/gpio/axp_gpio.c +1 -0
index 35585dc8ac9..14a99ce4c9c 100644
@@ -14,6 +14,7 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <errno.h>
+#include <sunxi_gpio.h>
 
 static int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val);
 
drivers/gpio/sunxi_gpio.c +1 -0
index 767996c10fc..49a6be6fd03 100644
@@ -17,6 +17,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <dt-bindings/gpio/gpio.h>
+#include <sunxi_gpio.h>
 
 #if !CONFIG_IS_ENABLED(DM_GPIO)
 static int sunxi_gpio_output(u32 pin, u32 val)
drivers/i2c/sun6i_p2wi.c +1 -1
index d221323295d..b8e07a533ca 100644
@@ -20,10 +20,10 @@
 #include <errno.h>
 #include <i2c.h>
 #include <reset.h>
+#include <sunxi_gpio.h>
 #include <time.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
-#include <asm/arch/gpio.h>
 #include <asm/arch/p2wi.h>
 #include <asm/arch/prcm.h>
 #include <asm/arch/sys_proto.h>
drivers/i2c/sun8i_rsb.c +1 -1
index 47fa05b6d1c..f36f2c7afac 100644
@@ -14,10 +14,10 @@
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <sunxi_gpio.h>
 #include <reset.h>
 #include <time.h>
 #include <asm/arch/cpu.h>
-#include <asm/arch/gpio.h>
 #include <asm/arch/prcm.h>
 #include <asm/arch/rsb.h>
 
drivers/mmc/sunxi_mmc.c +1 -0
index 1bb7b6d0e92..a9132af3f64 100644
@@ -21,6 +21,7 @@
 #include <asm/arch/cpu.h>
 #include <asm/arch/mmc.h>
 #include <linux/delay.h>
+#include <sunxi_gpio.h>
 
 #ifndef CCM_MMC_CTRL_MODE_SEL_NEW
 #define CCM_MMC_CTRL_MODE_SEL_NEW	0
drivers/pinctrl/sunxi/pinctrl-sunxi.c +1 -0
index 5ab3951ab52..8c12febcc0d 100644
@@ -7,6 +7,7 @@
 #include <dm/pinctrl.h>
 #include <errno.h>
 #include <malloc.h>
+#include <sunxi_gpio.h>
 
 #include <asm/gpio.h>
 
drivers/video/hitachi_tx18d42vm_lcd.c +1 -0
index 87c4d27438a..95984fe3d3d 100644
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 
 #include <asm/gpio.h>
+#include <sunxi_gpio.h>
 #include <errno.h>
 
 /*
drivers/video/ssd2828.c +0 -1
index 4cdcbe7755a..948f5e74d0f 100644
@@ -12,7 +12,6 @@
 #include <common.h>
 #include <malloc.h>
 #include <mipi_display.h>
-#include <asm/arch/gpio.h>
 #include <asm/gpio.h>
 #include <linux/delay.h>
 
drivers/video/sunxi/sunxi_display.c +1 -0
index 2ee6212c58d..7cc2f5577f3 100644
@@ -31,6 +31,7 @@
 #include <malloc.h>
 #include <video.h>
 #include <dm/uclass-internal.h>
+#include <sunxi_gpio.h>
 #include "../videomodes.h"
 #include "../anx9804.h"
 #include "../hitachi_tx18d42vm_lcd.h"
drivers/video/sunxi/sunxi_lcd.c +1 -0
index 8b9c3b2bfa9..7a01cc343ca 100644
@@ -17,6 +17,7 @@
 #include <asm/arch/lcdc.h>
 #include <asm/global_data.h>
 #include <asm/gpio.h>
+#include <sunxi_gpio.h>
 
 struct sunxi_lcd_priv {
 	struct display_timing timing;
include/sunxi_gpio.h renamed from arch/arm/include/asm/arch-sunxi/gpio.h +0 -0
similarity index 100%
rename from arch/arm/include/asm/arch-sunxi/gpio.h
rename to include/sunxi_gpio.h
Signature · 1 line
2.35.5
#12 lore raw

RFC PATCH 6/17 pinctrl: sunxi: move PIO_BASE into sunxi_gpio.h

In reply to Andre Przywara

On the Allwinner platform we were describing a quite comprehensive memory map in a per-SoC header unser arch/arm.
In the old days that was used by every driver, but nowadays it should only be needed by SPL drivers (not using the DT). Many addresses in there were never used, and some are not needed anymore.

To avoid a dependency on CPU specific headers in an arch specific directory, move the definition of the pinctroller MMIO base address into the sunxi_gpio.h header, because the SPL routines for GPIO should be the only one needing this address.
This is a first step towards getting rid of cpu_sun[x]i.h completely, and allows to remove the inclusion of that file from the sunxi_gpio.h header.

---
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h     |  2 --
 arch/arm/include/asm/arch-sunxi/cpu_sun50i_h6.h |  2 --
 arch/arm/include/asm/arch-sunxi/cpu_sun9i.h     |  2 --
 include/sunxi_gpio.h                            | 12 +++++++++++-
 4 files changed, 11 insertions(+), 7 deletions(-)
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +0 -2
index f7ecc790dbf..d6fe51f24bc 100644
@@ -91,7 +91,6 @@
 
 #define SUNXI_CCM_BASE			0x01c20000
 #define SUNXI_INTC_BASE			0x01c20400
-#define SUNXI_PIO_BASE			0x01c20800
 #define SUNXI_TIMER_BASE		0x01c20c00
 #ifndef CONFIG_SUNXI_GEN_SUN6I
 #define SUNXI_PWM_BASE			0x01c20e00
@@ -210,7 +209,6 @@ defined(CONFIG_MACH_SUN50I)
 
 #define SUNXI_R_TWI_BASE		0x01f02400
 #define SUNXI_R_UART_BASE		0x01f02800
-#define SUNXI_R_PIO_BASE		0x01f02c00
 #define SUN6I_P2WI_BASE			0x01f03400
 #define SUNXI_RSB_BASE			0x01f03400
 
arch/arm/include/asm/arch-sunxi/cpu_sun50i_h6.h +0 -2
index d9cf8ae0428..9b6bf843601 100644
@@ -22,7 +22,6 @@
 #define SUNXI_SIDC_BASE			0x03006000
 #define SUNXI_SID_BASE			0x03006200
 #define SUNXI_TIMER_BASE		0x03009000
-#define SUNXI_PIO_BASE			0x0300B000
 #define SUNXI_PSI_BASE			0x0300C000
 
 #define SUNXI_GIC400_BASE		0x03020000
@@ -68,7 +67,6 @@
 #define SUNXI_R_CPUCFG_BASE		0x07000400
 #define SUNXI_PRCM_BASE			0x07010000
 #define SUNXI_R_WDOG_BASE		0x07020400
-#define SUNXI_R_PIO_BASE		0x07022000
 #define SUNXI_R_UART_BASE		0x07080000
 #define SUNXI_R_TWI_BASE		0x07081400
 
arch/arm/include/asm/arch-sunxi/cpu_sun9i.h +0 -2
index 9c2d11b5901..20025be2319 100644
@@ -81,7 +81,6 @@
 /* APB0 Module */
 #define SUNXI_CCM_BASE			(REGS_APB0_BASE + 0x0000)
 #define SUNXI_CCMMODULE_BASE		(REGS_APB0_BASE + 0x0400)
-#define SUNXI_PIO_BASE			(REGS_APB0_BASE + 0x0800)
 #define SUNXI_TIMER_BASE		(REGS_APB0_BASE + 0x0C00)
 #define SUNXI_PWM_BASE			(REGS_APB0_BASE + 0x1400)
 #define SUNXI_LRADC_BASE		(REGS_APB0_BASE + 0x1800)
@@ -102,7 +101,6 @@
 /* RCPUS Module */
 #define SUNXI_PRCM_BASE			(REGS_RCPUS_BASE + 0x1400)
 #define SUNXI_R_UART_BASE		(REGS_RCPUS_BASE + 0x2800)
-#define SUNXI_R_PIO_BASE		(REGS_RCPUS_BASE + 0x2c00)
 #define SUNXI_RSB_BASE			(REGS_RCPUS_BASE + 0x3400)
 
 /* Misc. */
include/sunxi_gpio.h +11 -1
index 42ca03d8c18..5ac476f960d 100644
@@ -9,7 +9,17 @@
 #define _SUNXI_GPIO_H
 
 #include <linux/types.h>
-#include <asm/arch/cpu.h>
+
+#if defined(CONFIG_MACH_SUN9I)
+#define SUNXI_PIO_BASE		0x06000800
+#define SUNXI_R_PIO_BASE	0x08002c00
+#elif defined(CONFIG_SUN50I_GEN_H6)
+#define SUNXI_PIO_BASE		0x0300b000
+#define SUNXI_R_PIO_BASE	0x07022000
+#else
+#define SUNXI_PIO_BASE		0x01c20800
+#define SUNXI_R_PIO_BASE	0x01f02c00
+#endif
 
 /*
  * sunxi has 9 banks of gpio, they are:
Signature · 1 line
2.35.5
#13 lore raw

RFC PATCH 7/17 pinctrl: sunxi: add new D1 pinctrl support

In reply to Andre Przywara

For the first time since at least the Allwinner A10 SoCs, the D1 (and related cores) use a new pincontroller MMIO register layout, so we cannot use our hardcoded, fixed offsets anymore.
Ideally this would all be handled by devicetree and DM drivers, but for the DT-less SPL we still need the legacy interfaces.

Add a new Kconfig symbol to differenciate between the two generations of pincontrollers, and just use that to just switch some basic symbols. The rest is already abstracted enough, so works out of the box.

---
 arch/arm/mach-sunxi/Kconfig |  6 ++++++
 include/sunxi_gpio.h        | 26 +++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)
arch/arm/mach-sunxi/Kconfig +6 -0
index 6220175d612..5e019948f85 100644
@@ -113,6 +113,12 @@ config SUNXI_SRAM_ADDRESS
 config SUNXI_A64_TIMER_ERRATUM
 	bool
 
+config SUNXI_NEW_PINCTRL
+	bool
+	---help---
+	The Allwinner D1 and other new SoCs use a different register map
+	for the GPIO block, which we need to know about in the SPL.
+
 # Note only one of these may be selected at a time! But hidden choices are
 # not supported by Kconfig
 config SUNXI_GEN_SUN4I
include/sunxi_gpio.h +21 -5
index 5ac476f960d..2f8b220f750 100644
@@ -68,15 +68,32 @@
 #define GPIO_DAT_REG_OFFSET	0x10
 
 #define GPIO_DRV_REG_OFFSET	0x14
-#define GPIO_DRV_INDEX(pin)	(((pin) & 0x1f) >> 4)
-#define GPIO_DRV_OFFSET(pin)	((((pin) & 0x1f) & 0xf) << 1)
+
+/*		Newer SoCs use a slightly different register layout */
+#ifdef CONFIG_SUNXI_NEW_PINCTRL
+/* pin drive strength: 4 bits per pin */
+#define GPIO_DRV_INDEX(pin)	((pin) / 8)
+#define GPIO_DRV_OFFSET(pin)	(((pin) % 8) * 4)
+
+#define GPIO_PULL_REG_OFFSET	0x24
+
+#define SUNXI_PINCTRL_BANK_SIZE	0x30
+#define SUNXI_GPIO_DISABLE	0xf
+
+#else /* older generation pin controllers */
+/* pin drive strength: 2 bits per pin */
+#define GPIO_DRV_INDEX(pin)	((pin) / 16)
+#define GPIO_DRV_OFFSET(pin)	(((pin) % 16) * 2)
 
 #define GPIO_PULL_REG_OFFSET	0x1c
+
+#define SUNXI_PINCTRL_BANK_SIZE	0x24
+#define SUNXI_GPIO_DISABLE	0x7
+#endif
+
 #define GPIO_PULL_INDEX(pin)	(((pin) & 0x1f) >> 4)
 #define GPIO_PULL_OFFSET(pin)	((((pin) & 0x1f) & 0xf) << 1)
 
-#define SUNXI_PINCTRL_BANK_SIZE 0x24
-
 static inline void* BANK_TO_GPIO(int bank)
 {
 	void *pio_base;
@@ -132,7 +149,6 @@ enum sunxi_gpio_number {
 /* GPIO pin function config */
 #define SUNXI_GPIO_INPUT	0
 #define SUNXI_GPIO_OUTPUT	1
-#define SUNXI_GPIO_DISABLE	7
 
 #define SUN8I_H3_GPA_UART0	2
 #define SUN8I_H3_GPA_UART2	2
Signature · 1 line
2.35.5
#14 lore raw

RFC PATCH 8/17 sunxi: introduce NCAT2 generation model

In reply to Andre Przywara

Allwinner seems to typically stick to a common MMIO memory map for several SoCs, but from time to time does some breaking changes, which also introduce new generations of some peripherals. The last time this happened with the H6, which apart from re-organising the base addresses also changed the clock controller significantly. We added a CONFIG_SUN50I_GEN_H6 symbol back then to mark SoCs sharing those traits.

Now the Allwinner D1 changes the memory map again, and also extends the pincontroller, among other peripherals.
To mark this generation of SoCs, add a CONFIG_SUNXI_GEN_NCAT2 symbol, this name is reportedly used in the Allwinner BSP code, and prevents us from inventing our own name.

Add this new symbol to some guards that were already checking for the H6 generation, since many features are shared between the two (like the renovated clock controller).

This paves the way to introduce a first user of this generation.

---
 arch/arm/include/asm/arch-sunxi/clock.h       |  2 +-
 arch/arm/include/asm/arch-sunxi/cpu.h         |  2 +
 .../include/asm/arch-sunxi/cpu_sunxi_ncat2.h  | 54 +++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/mmc.h         |  2 +-
 arch/arm/include/asm/arch-sunxi/prcm.h        |  2 +-
 arch/arm/include/asm/arch-sunxi/timer.h       |  2 +-
 arch/arm/mach-sunxi/Kconfig                   | 14 ++++-
 arch/arm/mach-sunxi/Makefile                  |  1 +
 arch/arm/mach-sunxi/board.c                   |  4 +-
 common/spl/Kconfig                            |  2 +-
 drivers/mmc/sunxi_mmc.c                       | 10 ++--
 include/sunxi_gpio.h                          |  3 ++
 12 files changed, 86 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h
arch/arm/include/asm/arch-sunxi/clock.h +1 -1
index 2cfd5407423..3d34261b0e5 100644
@@ -16,7 +16,7 @@
 /* clock control module regs definition */
 #if defined(CONFIG_MACH_SUN8I_A83T)
 #include <asm/arch/clock_sun8i_a83t.h>
-#elif defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 #include <asm/arch/clock_sun50i_h6.h>
 #elif defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I) || \
       defined(CONFIG_MACH_SUN50I) || defined(CONFIG_MACH_SUNIV)
arch/arm/include/asm/arch-sunxi/cpu.h +2 -0
index b08f2023748..768c6572d6b 100644
@@ -10,6 +10,8 @@
 #include <asm/arch/cpu_sun9i.h>
 #elif defined(CONFIG_SUN50I_GEN_H6)
 #include <asm/arch/cpu_sun50i_h6.h>
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#include <asm/arch/cpu_sunxi_ncat2.h>
 #else
 #include <asm/arch/cpu_sun4i.h>
 #endif
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h new file +54 -0

54 lines not on this page · raw message

arch/arm/include/asm/arch-sunxi/mmc.h +1 -1
index 5daacf10eb1..8ed3e0459c9 100644
@@ -45,7 +45,7 @@ struct sunxi_mmc {
 	u32 chda;		/* 0x90 */
 	u32 cbda;		/* 0x94 */
 	u32 res2[26];
-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 	u32 res3[17];
 	u32 samp_dl;
 	u32 res4[46];
arch/arm/include/asm/arch-sunxi/prcm.h +1 -1
index 5106076f5e9..c5418cfd28d 100644
@@ -9,7 +9,7 @@
 #define _SUNXI_PRCM_H
 
 /* prcm regs definition */
-#if defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 #include <asm/arch/prcm_sun50i.h>
 #else
 #include <asm/arch/prcm_sun6i.h>
arch/arm/include/asm/arch-sunxi/timer.h +1 -1
index bb5626d893b..e17db8588e2 100644
@@ -76,7 +76,7 @@ struct sunxi_timer_reg {
 	struct sunxi_tgp tgp[4];
 	u8 res5[8];
 	u32 cpu_cfg;
-#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 	u8 res3[16];
 	struct sunxi_wdog wdog[5];	/* We have 5 watchdogs */
 #endif
arch/arm/mach-sunxi/Kconfig +13 -1
index 5e019948f85..b59db212fa8 100644
@@ -102,7 +102,7 @@ config AXP_PMIC_BUS
 config SUNXI_SRAM_ADDRESS
 	hex
 	default 0x10000 if MACH_SUN9I || MACH_SUN50I || MACH_SUN50I_H5
-	default 0x20000 if SUN50I_GEN_H6
+	default 0x20000 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2
 	default 0x0
 	---help---
 	Older Allwinner SoCs have their mask boot ROM mapped just below 4GB,
@@ -144,6 +144,16 @@ config SUN50I_GEN_H6
 	Select this for sunxi SoCs which have H6 like peripherals, clocks
 	and memory map.
 
+config SUNXI_GEN_NCAT2
+	bool
+	select FIT
+	select SPL_LOAD_FIT
+	select MMC_SUNXI_HAS_NEW_MODE
+	select SUPPORT_SPL
+	---help---
+	Select this for sunxi SoCs which have D1 like peripherals, clocks
+	and memory map.
+
 config SUNXI_DRAM_DW
 	bool
 	---help---
@@ -787,6 +797,7 @@ config VIDEO_SUNXI
 	depends on !MACH_SUN9I
 	depends on !MACH_SUN50I
 	depends on !SUN50I_GEN_H6
+	depends on !SUNXI_GEN_NCAT2
 	select VIDEO
 	select DISPLAY
 	imply VIDEO_DT_SIMPLEFB
@@ -1000,6 +1011,7 @@ config SPL_STACK_R_ADDR
 	default 0x2fe00000 if MACH_SUN9I
 	default 0x4fe00000 if MACH_SUN50I
 	default 0x4fe00000 if SUN50I_GEN_H6
+	default 0x4fe00000 if SUNXI_GEN_NCAT2
 
 config SPL_SPI_SUNXI
 	bool "Support for SPI Flash on Allwinner SoCs in SPL"
arch/arm/mach-sunxi/Makefile +1 -0
index 671211e9322..1d4c70ec352 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_MACH_SUN8I)	+= clock_sun6i.o
 endif
 obj-$(CONFIG_MACH_SUN9I)	+= clock_sun9i.o gtbus_sun9i.o
 obj-$(CONFIG_SUN50I_GEN_H6)	+= clock_sun50i_h6.o
+obj-$(CONFIG_SUNXI_GEN_NCAT2)	+= clock_sun50i_h6.o
 ifndef CONFIG_ARM64
 obj-y	+= timer.o
 endif
arch/arm/mach-sunxi/board.c +2 -2
index b6ffbff883c..3763ec3d2e4 100644
@@ -177,7 +177,7 @@ static int gpio_init(void)
 #error Unsupported console port number. Please fix pin mux settings in board.c
 #endif
 
-#ifdef CONFIG_SUN50I_GEN_H6
+#if defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 	/* Update PIO power bias configuration by copy hardware detected value */
 	val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
 	writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
@@ -475,7 +475,7 @@ void reset_cpu(void)
 		/* sun5i sometimes gets stuck without this */
 		writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
 	}
-#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 #if defined(CONFIG_MACH_SUN50I_H6)
 	/* WDOG is broken for some H6 rev. use the R_WDOG instead */
 	static const struct sunxi_wdog *wdog =
common/spl/Kconfig +1 -1
index fef01bdd7da..fdd64db498f 100644
@@ -265,7 +265,7 @@ config SPL_TEXT_BASE
 	default 0x402F0400 if AM33XX
 	default 0x40301350 if OMAP54XX
 	default 0x10060 if MACH_SUN50I || MACH_SUN50I_H5 || MACH_SUN9I
-	default 0x20060 if SUN50I_GEN_H6
+	default 0x20060 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2
 	default 0x00060 if ARCH_SUNXI
 	default 0xfffc0000 if ARCH_ZYNQMP
 	default 0x0
drivers/mmc/sunxi_mmc.c +6 -4
index a9132af3f64..6ce2729473c 100644
@@ -114,6 +114,7 @@ static bool sunxi_mmc_can_calibrate(void)
 	return IS_ENABLED(CONFIG_MACH_SUN50I) ||
 	       IS_ENABLED(CONFIG_MACH_SUN50I_H5) ||
 	       IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
+	       IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2) ||
 	       IS_ENABLED(CONFIG_MACH_SUN8I_R40);
 }
 
@@ -248,7 +249,7 @@ static int mmc_config_clock(struct sunxi_mmc_priv *priv, struct mmc *mmc)
 	rval &= ~SUNXI_MMC_CLK_DIVIDER_MASK;
 	writel(rval, &priv->reg->clkcr);
 
-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
 	/* A64 supports calibration of delays on MMC controller and we
 	 * have to set delay of zero before starting calibration.
 	 * Allwinner BSP driver sets a delay only in the case of
@@ -559,7 +560,8 @@ struct mmc *sunxi_mmc_init(int sdc_no)
 	cfg->host_caps = MMC_MODE_4BIT;
 
 	if ((IS_ENABLED(CONFIG_MACH_SUN50I) || IS_ENABLED(CONFIG_MACH_SUN8I) ||
-	    IS_ENABLED(CONFIG_SUN50I_GEN_H6)) && (sdc_no == 2))
+	    IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
+	    IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2)) && (sdc_no == 2))
 		cfg->host_caps = MMC_MODE_8BIT;
 
 	cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
@@ -573,7 +575,7 @@ struct mmc *sunxi_mmc_init(int sdc_no)
 
 	/* config ahb clock */
 	debug("init mmc %d clock and io\n", sdc_no);
-#if !defined(CONFIG_SUN50I_GEN_H6)
+#if !defined(CONFIG_SUN50I_GEN_H6) && !defined(CONFIG_SUNXI_GEN_NCAT2)
 	setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_MMC(sdc_no));
 
 #ifdef CONFIG_SUNXI_GEN_SUN6I
@@ -647,7 +649,7 @@ static unsigned get_mclk_offset(void)
 	if (IS_ENABLED(CONFIG_MACH_SUN9I_A80))
 		return 0x410;
 
-	if (IS_ENABLED(CONFIG_SUN50I_GEN_H6))
+	if (IS_ENABLED(CONFIG_SUN50I_GEN_H6) || IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2))
 		return 0x830;
 
 	return 0x88;
include/sunxi_gpio.h +3 -0
index 2f8b220f750..04d7aa3d632 100644
@@ -16,6 +16,9 @@
 #elif defined(CONFIG_SUN50I_GEN_H6)
 #define SUNXI_PIO_BASE		0x0300b000
 #define SUNXI_R_PIO_BASE	0x07022000
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#define SUNXI_PIO_BASE		0x02000000
+#define SUNXI_R_PIO_BASE	0
 #else
 #define SUNXI_PIO_BASE		0x01c20800
 #define SUNXI_R_PIO_BASE	0x01f02c00
Signature · 1 line
2.35.5
#15 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

Quoted 10 lines · 在 2022-12-06星期二的 00:45 +0000,Andre Przywara写道:

Allwinner seems to typically stick to a common MMIO memory map for several SoCs, but from time to time does some breaking changes, which also introduce new generations of some peripherals. The last time this
happened with the H6, which apart from re-organising the base addresses
also changed the clock controller significantly. We added a CONFIG_SUN50I_GEN_H6 symbol back then to mark SoCs sharing those traits.

Quoted 7 lines

Now the Allwinner D1 changes the memory map again, and also extends the
pincontroller, among other peripherals.
To mark this generation of SoCs, add a CONFIG_SUNXI_GEN_NCAT2 symbol, this name is reportedly used in the Allwinner BSP code, and prevents us
from inventing our own name.

Should we also rename the misleading GEN_SUN50I_H6 to GEN_NCAT ?

Quoted 337 lines

Add this new symbol to some guards that were already checking for the H6
generation, since many features are shared between the two (like the renovated clock controller).

This paves the way to introduce a first user of this generation.

---
 arch/arm/include/asm/arch-sunxi/clock.h       |  2 +- arch/arm/include/asm/arch-sunxi/cpu.h         |  2 + .../include/asm/arch-sunxi/cpu_sunxi_ncat2.h  | 54
+++++++++++++++++++
 arch/arm/include/asm/arch-sunxi/mmc.h         |  2 +- arch/arm/include/asm/arch-sunxi/prcm.h        |  2 +- arch/arm/include/asm/arch-sunxi/timer.h       |  2 +- arch/arm/mach-sunxi/Kconfig                   | 14 ++++- arch/arm/mach-sunxi/Makefile                  |  1 + arch/arm/mach-sunxi/board.c                   |  4 +- common/spl/Kconfig                            |  2 +- drivers/mmc/sunxi_mmc.c                       | 10 ++-- include/sunxi_gpio.h                          |  3 ++

 12 files changed, 86 insertions(+), 12 deletions(-)

 create mode 100644 arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h

arch/arm/include/asm/arch-sunxi/clock.h +1 -1
index 2cfd5407423..3d34261b0e5 100644
@@ -16,7 +16,7 @@
  /* clock control module regs definition */
  #if defined(CONFIG_MACH_SUN8I_A83T)
  #include <asm/arch/clock_sun8i_a83t.h>
-#elif defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUN50I_GEN_H6) ||
 defined(CONFIG_SUNXI_GEN_NCAT2)
  #include <asm/arch/clock_sun50i_h6.h>
  #elif defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I) || \

       defined(CONFIG_MACH_SUN50I) || defined(CONFIG_MACH_SUNIV)

arch/arm/include/asm/arch-sunxi/cpu.h +2 -0
index b08f2023748..768c6572d6b 100644
@@ -10,6 +10,8 @@
  #include <asm/arch/cpu_sun9i.h>
  #elif defined(CONFIG_SUN50I_GEN_H6)
  #include <asm/arch/cpu_sun50i_h6.h>
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#include <asm/arch/cpu_sunxi_ncat2.h>
  #else
  #include <asm/arch/cpu_sun4i.h>
  #endif
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h new file +16 -0
new file mode 100644
index 00000000000..13093085a5e
@@ -0,0 +1,54 @@
+/*
+ * (C) Copyright 2022 Arm Limited
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef _SUNXI_CPU_SUNXI_NCAT2_H
+#define _SUNXI_CPU_SUNXI_NCAT2_H
+
+#define SUNXI_SRAM_A1_BASE             CONFIG_SUNXI_SRAM_ADDRESS
+#define SUNXI_SRAM_C_BASE              0x00028000
+#define SUNXI_SRAM_A2_BASE             0x00100000
+
+#define SUNXI_SRAMC_BASE               0x02800000
+#define SUNXI_CCM_BASE                 0x02001000
+/* SID address space starts at 0x03006000, but e-fuse is at offset

0x200 */

arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h new file +38 -0
+#define SUNXI_SIDC_BASE                        0x03006000
+#define SUNXI_SID_BASE                 0x03006200
+#define SUNXI_TIMER_BASE               0x02050000
+
+#ifdef CONFIG_MACH_SUN50I_H6
+#define SUNXI_DRAM_COM_BASE            0x04002000
+#define SUNXI_DRAM_CTL0_BASE           0x04003000
+#define SUNXI_DRAM_PHY0_BASE           0x04005000
+#endif
+#define SUNXI_MMC0_BASE                        0x04020000
+#define SUNXI_MMC1_BASE                        0x04021000
+#define SUNXI_MMC2_BASE                        0x04022000
+
+#define SUNXI_UART0_BASE               0x02500000
+#define SUNXI_UART1_BASE               0x02500400
+#define SUNXI_UART2_BASE               0x02500800
+#define SUNXI_UART3_BASE               0x02500C00
+#define SUNXI_TWI0_BASE                        0x02502000
+#define SUNXI_TWI1_BASE                        0x02502400
+#define SUNXI_TWI2_BASE                        0x02502800
+#define SUNXI_TWI3_BASE                        0x02502C00
+#define SUNXI_SPI0_BASE                        0x04025000
+#define SUNXI_SPI1_BASE                        0x04026000
+
+#define SUNXI_RTC_BASE                 0x07000000
+#define SUNXI_R_CPUCFG_BASE            0x07000400
+#define SUNXI_PRCM_BASE                        0x07010000
+#define SUNXI_R_WDOG_BASE              0x07020400
+#define SUNXI_R_UART_BASE              0x07080000
+#define SUNXI_R_TWI_BASE               0x07081400
+
+#ifndef __ASSEMBLY__
+void sunxi_board_init(void);
+void sunxi_reset(void);
+int sunxi_get_sid(unsigned int *sid);
+#endif
+
+#endif /* _SUNXI_CPU_SUNXI_NCAT2_H */
arch/arm/include/asm/arch-sunxi/mmc.h +0 -0
index 5daacf10eb1..8ed3e0459c9 100644
@@ -45,7 +45,7 @@ struct sunxi_mmc {

        u32 chda;               /* 0x90 */
        u32 cbda;               /* 0x94 */
        u32 res2[26];

arch/arm/include/asm/arch-sunxi/mmc.h +1 -1
-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)

|| defined(CONFIG_SUNXI_GEN_NCAT2)
        u32 res3[17];
        u32 samp_dl;
        u32 res4[46];

arch/arm/include/asm/arch-sunxi/prcm.h +0 -0
index 5106076f5e9..c5418cfd28d 100644
@@ -9,7 +9,7 @@
  #define _SUNXI_PRCM_H


 /* prcm regs definition */

arch/arm/include/asm/arch-sunxi/prcm.h +1 -1
-#if defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)

 #include <asm/arch/prcm_sun50i.h>
 #else
 #include <asm/arch/prcm_sun6i.h>

arch/arm/include/asm/arch-sunxi/timer.h +1 -1
index bb5626d893b..e17db8588e2 100644
@@ -76,7 +76,7 @@ struct sunxi_timer_reg {
         struct sunxi_tgp tgp[4];
         u8 res5[8];
         u32 cpu_cfg;
-#elif defined(CONFIG_SUNXI_GEN_SUN6I) ||
 defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUNXI_GEN_SUN6I) ||
 defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
         u8 res3[16];

        struct sunxi_wdog wdog[5];      /* We have 5 watchdogs */ #endif

arch/arm/mach- renamed from arch/arm/mach-sunxi/Kconfig +0 -0

sunxi/Kconfig
index 5e019948f85..b59db212fa8 100644

arch/arm/mach-sunxi/Kconfig +0 -0
@@ -102,7 +102,7 @@ config AXP_PMIC_BUS

 config SUNXI_SRAM_ADDRESS
        hex
        default 0x10000 if MACH_SUN9I || MACH_SUN50I || MACH_SUN50I_H5
-       default 0x20000 if SUN50I_GEN_H6
+       default 0x20000 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2 default 0x0
        ---help---
        Older Allwinner SoCs have their mask boot ROM mapped just below 4GB,

arch/arm/mach-sunxi/Kconfig +0 -0
@@ -144,6 +144,16 @@ config SUN50I_GEN_H6
         Select this for sunxi SoCs which have H6 like peripherals,

clocks
        and memory map.

+config SUNXI_GEN_NCAT2
+       bool
+       select FIT
+       select SPL_LOAD_FIT
+       select MMC_SUNXI_HAS_NEW_MODE
+       select SUPPORT_SPL
+       ---help---
+       Select this for sunxi SoCs which have D1 like peripherals, clocks
+       and memory map.
+
 config SUNXI_DRAM_DW
        bool
        ---help---

arch/arm/mach-sunxi/Kconfig +0 -0
@@ -787,6 +797,7 @@ config VIDEO_SUNXI

        depends on !MACH_SUN9I
        depends on !MACH_SUN50I
        depends on !SUN50I_GEN_H6
+       depends on !SUNXI_GEN_NCAT2
        select VIDEO
        select DISPLAY
        imply VIDEO_DT_SIMPLEFB

arch/arm/mach-sunxi/Kconfig +0 -0
@@ -1000,6 +1011,7 @@ config SPL_STACK_R_ADDR

        default 0x2fe00000 if MACH_SUN9I
        default 0x4fe00000 if MACH_SUN50I
        default 0x4fe00000 if SUN50I_GEN_H6
+       default 0x4fe00000 if SUNXI_GEN_NCAT2

 config SPL_SPI_SUNXI
        bool "Support for SPI Flash on Allwinner SoCs in SPL"

arch/arm/mach- renamed from arch/arm/mach-sunxi/Makefile +0 -0

sunxi/Makefile
index 671211e9322..1d4c70ec352 100644

arch/arm/mach-sunxi/Makefile +0 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_MACH_SUN8I)      += clock_sun6i.o

 endif
 obj-$(CONFIG_MACH_SUN9I)       += clock_sun9i.o gtbus_sun9i.o obj-$(CONFIG_SUN50I_GEN_H6)    += clock_sun50i_h6.o +obj-$(CONFIG_SUNXI_GEN_NCAT2)  += clock_sun50i_h6.o ifndef CONFIG_ARM64
 obj-y  += timer.o
 endif

arch/arm/mach- renamed from arch/arm/mach-sunxi/board.c +0 -0

sunxi/board.c
index b6ffbff883c..3763ec3d2e4 100644

arch/arm/mach-sunxi/board.c +0 -0
@@ -177,7 +177,7 @@ static int gpio_init(void)
  #error Unsupported console port number. Please fix pin mux settings

in board.c
 #endif

arch/arm/mach-sunxi/board.c +1 -1
-#ifdef CONFIG_SUN50I_GEN_H6
+#if defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)

        /* Update PIO power bias configuration by copy hardware detected value */
        val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL); writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);

arch/arm/mach-sunxi/board.c +1 -1
@@ -475,7 +475,7 @@ void reset_cpu(void)
                 /* sun5i sometimes gets stuck without this */
                 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
         }
-#elif defined(CONFIG_SUNXI_GEN_SUN6I) ||
 defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUNXI_GEN_SUN6I) ||
 defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
  #if defined(CONFIG_MACH_SUN50I_H6)

        /* WDOG is broken for some H6 rev. use the R_WDOG instead */ static const struct sunxi_wdog *wdog =

common/spl/Kconfig +0 -0
index fef01bdd7da..fdd64db498f 100644
@@ -265,7 +265,7 @@ config SPL_TEXT_BASE

        default 0x402F0400 if AM33XX
        default 0x40301350 if OMAP54XX
        default 0x10060 if MACH_SUN50I || MACH_SUN50I_H5 || MACH_SUN9I
-       default 0x20060 if SUN50I_GEN_H6
+       default 0x20060 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2 default 0x00060 if ARCH_SUNXI
        default 0xfffc0000 if ARCH_ZYNQMP
        default 0x0

drivers/mmc/sunxi_mmc.c +0 -0
index a9132af3f64..6ce2729473c 100644
@@ -114,6 +114,7 @@ static bool sunxi_mmc_can_calibrate(void)

        return IS_ENABLED(CONFIG_MACH_SUN50I) ||

               IS_ENABLED(CONFIG_MACH_SUN50I_H5) ||
               IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
+              IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2) ||

               IS_ENABLED(CONFIG_MACH_SUN8I_R40);
 }

drivers/mmc/sunxi_mmc.c +0 -0
@@ -248,7 +249,7 @@ static int mmc_config_clock(struct sunxi_mmc_priv
 *priv, struct mmc *mmc)
         rval &= ~SUNXI_MMC_CLK_DIVIDER_MASK;
         writel(rval, &priv->reg->clkcr);

drivers/mmc/sunxi_mmc.c +1 -1
-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)

|| defined(CONFIG_SUNXI_GEN_NCAT2)
        /* A64 supports calibration of delays on MMC controller and we
         * have to set delay of zero before starting calibration.
         * Allwinner BSP driver sets a delay only in the case of

drivers/mmc/sunxi_mmc.c +0 -0
@@ -559,7 +560,8 @@ struct mmc *sunxi_mmc_init(int sdc_no)
         cfg->host_caps = MMC_MODE_4BIT;


        if ((IS_ENABLED(CONFIG_MACH_SUN50I) || IS_ENABLED(CONFIG_MACH_SUN8I) ||
-           IS_ENABLED(CONFIG_SUN50I_GEN_H6)) && (sdc_no == 2)) +           IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
+           IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2)) && (sdc_no == 2)) cfg->host_caps = MMC_MODE_8BIT;

        cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;

drivers/mmc/sunxi_mmc.c +0 -0
@@ -573,7 +575,7 @@ struct mmc *sunxi_mmc_init(int sdc_no)


        /* config ahb clock */
        debug("init mmc %d clock and io\n", sdc_no);

drivers/mmc/sunxi_mmc.c +1 -1
-#if !defined(CONFIG_SUN50I_GEN_H6)
+#if !defined(CONFIG_SUN50I_GEN_H6) &&

!defined(CONFIG_SUNXI_GEN_NCAT2)
        setbits_le32(&ccm->ahb_gate0, 1 <<
AHB_GATE_OFFSET_MMC(sdc_no));

 #ifdef CONFIG_SUNXI_GEN_SUN6I

drivers/mmc/sunxi_mmc.c +0 -0
@@ -647,7 +649,7 @@ static unsigned get_mclk_offset(void)
         if (IS_ENABLED(CONFIG_MACH_SUN9I_A80))
                 return 0x410;


-       if (IS_ENABLED(CONFIG_SUN50I_GEN_H6))
+       if (IS_ENABLED(CONFIG_SUN50I_GEN_H6) ||
IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2))
                return 0x830;

        return 0x88;

include/sunxi_gpio.h +3 -0
index 2f8b220f750..04d7aa3d632 100644
@@ -16,6 +16,9 @@
  #elif defined(CONFIG_SUN50I_GEN_H6)
  #define SUNXI_PIO_BASE         0x0300b000
  #define SUNXI_R_PIO_BASE       0x07022000
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#define SUNXI_PIO_BASE         0x02000000
+#define SUNXI_R_PIO_BASE       0
  #else
  #define SUNXI_PIO_BASE         0x01c20800
  #define SUNXI_R_PIO_BASE       0x01f02c00
#16 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

In reply to Andre Przywara

Hi Andre! Thank you for your efforts on this patchset; I've been test-driving it a bit myself this week.

arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h line 46

Quoted 6 lines · Andre Przywara
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h new file +6 -0
+#define SUNXI_RTC_BASE			0x07000000
+#define SUNXI_R_CPUCFG_BASE		0x07000400
+#define SUNXI_PRCM_BASE			0x07010000
+#define SUNXI_R_WDOG_BASE		0x07020400
+#define SUNXI_R_UART_BASE		0x07080000
+#define SUNXI_R_TWI_BASE		0x07081400

How sure are we that this memory map is consistent across the whole NCAT2 family? The documentation for my target (T113-S3) puts the RTC base at 0x07090000, for example. I find no mention of there being a PRCM peripheral in this particular chip either.

common/spl/Kconfig config SPL_TEXT_BASE · line 271

Quoted 13 lines
common/spl/Kconfig +1 -1
index fef01bdd7da..fdd64db498f 100644
@@ -265,7 +265,7 @@ config SPL_TEXT_BASE
  	default 0x402F0400 if AM33XX
  	default 0x40301350 if OMAP54XX
  	default 0x10060 if MACH_SUN50I || MACH_SUN50I_H5 || MACH_SUN9I
-	default 0x20060 if SUN50I_GEN_H6
+	default 0x20060 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2
  	default 0x00060 if ARCH_SUNXI
  	default 0xfffc0000 if ARCH_ZYNQMP
  	default 0x0

Would it also be good to change the default for CONFIG_SPL_STACK? As-is it defaults to 0x8000, which would put it in the BROM region. Allwinner's boot0 starts its stack at 0x48000, which I've been using.

Quoted 5 lines
include/sunxi_gpio.h +0 -0
index 2f8b220f750..04d7aa3d632 100644

include/sunxi_gpio.h line 24

Quoted 9 lines
include/sunxi_gpio.h +3 -0
@@ -16,6 +16,9 @@
  #elif defined(CONFIG_SUN50I_GEN_H6)
  #define SUNXI_PIO_BASE		0x0300b000
  #define SUNXI_R_PIO_BASE	0x07022000
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#define SUNXI_PIO_BASE		0x02000000
+#define SUNXI_R_PIO_BASE	0
  #else
  #define SUNXI_PIO_BASE		0x01c20800
  #define SUNXI_R_PIO_BASE	0x01f02c00

Code elsewhere assumes that SUNXI_R_PIO_BASE is nonzero; on my local branch in particular I had to update arch/arm/mach-sunxi/board.c:gpio_init. Perhaps it would be better to leave SUNXI_R_PIO_BASE undefined in the chips where this gadget is missing?

Much gratitude,
Sam

#17 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

On Mon, 15 May 2023 20:32:52 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 2 lines

Hi Andre! Thank you for your efforts on this patchset; I've been test-driving it a bit myself this week.

many thanks for having a look, that's much appreciated!

Quoted 13 lines · Andre Przywara

arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h line 46

Quoted 7 lines
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h new file +6 -0
+#define SUNXI_RTC_BASE			0x07000000
+#define SUNXI_R_CPUCFG_BASE		0x07000400
+#define SUNXI_PRCM_BASE			0x07010000
+#define SUNXI_R_WDOG_BASE		0x07020400
+#define SUNXI_R_UART_BASE		0x07080000
+#define SUNXI_R_TWI_BASE		0x07081400  

How sure are we that this memory map is consistent across the whole NCAT2 family? The documentation for my target (T113-S3) puts the RTC base at 0x07090000, for example. I find no mention of there being a PRCM peripheral in this particular chip either.

This whole memory map is somewhat of a legacy. Apart from a few addresses for the SPL needs we shouldn't have those defines at all. Some symbols are needed because there are other macros using them, although these then are eventually unused.
I have some patches to remove most of the symbols, and patch 14/17 demonstrates some idea how to pin this down to what's really needed.

For this particular case: this was copied from the H6 memory map, some addresses are just plain wrong for the D1 family. I will try to remove them as much as possible, leaving only the ones needed in.

Quoted 9 lines
Quoted 9 lines
common/spl/Kconfig +0 -1
index fef01bdd7da..fdd64db498f 100644
@@ -265,7 +265,7 @@ config SPL_TEXT_BASE
  	default 0x402F0400 if AM33XX
  	default 0x40301350 if OMAP54XX
  	default 0x10060 if MACH_SUN50I || MACH_SUN50I_H5 || MACH_SUN9I
-	default 0x20060 if SUN50I_GEN_H6
Quoted 8 lines

common/spl/Kconfig config SPL_TEXT_BASE · line 271

Quoted 4 lines
common/spl/Kconfig +1 -0
+	default 0x20060 if SUN50I_GEN_H6 || SUNXI_GEN_NCAT2
  	default 0x00060 if ARCH_SUNXI
  	default 0xfffc0000 if ARCH_ZYNQMP
  	default 0x0  

Would it also be good to change the default for CONFIG_SPL_STACK? As-is it defaults to 0x8000, which would put it in the BROM region. Allwinner's boot0 starts its stack at 0x48000, which I've been using.

Yeah, well spotted, this was a bug in this early RTC post. I never ran the SPL, because the DRAM code was missing still. I fixed the stack pointer meanwhile in an updated (and working) version on Github:
https://github.com/apritzel/u-boot/commit/d5fa559abdf2#diff-19adb575625e29e7a996e0ffb1a266e24239d9b004f17154616220a3f17a24ed

Quoted 11 lines
Quoted 11 lines
include/sunxi_gpio.h +3 -0
index 2f8b220f750..04d7aa3d632 100644
@@ -16,6 +16,9 @@
  #elif defined(CONFIG_SUN50I_GEN_H6)
  #define SUNXI_PIO_BASE		0x0300b000
  #define SUNXI_R_PIO_BASE	0x07022000
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#define SUNXI_PIO_BASE		0x02000000
+#define SUNXI_R_PIO_BASE	0
Quoted 8 lines

include/sunxi_gpio.h line 24

Quoted 3 lines
include/sunxi_gpio.h +0 -0
  #else
  #define SUNXI_PIO_BASE		0x01c20800
  #define SUNXI_R_PIO_BASE	0x01f02c00  

Code elsewhere assumes that SUNXI_R_PIO_BASE is nonzero; on my local branch in particular I had to update arch/arm/mach-sunxi/board.c:gpio_init. Perhaps it would be better to leave SUNXI_R_PIO_BASE undefined in the chips where this gadget is missing?

I think leaving it undefined causes more problems, doesn't it? Looking at #define BANK_TO_GPIO(bank) in arch/arm/include/asm/arch-sunxi/gpio.h, specifically. I am saying that because that's what I tried first ;-)

So where did you see problems? If you would (wrongly) reference PortL somewhere in SPL GPIO code, it would use a wrong pointer, but at least the code would still compile fine, wouldn't it?

Cheers,
Andre

P.S. Could you try the github post? Then compiled and booted fine for me, and includes the DRAM code as well now:
https://github.com/apritzel/u-boot/commits/t113s-mq-r-WIP

#18 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

Quoted 10 lines · Andre Przywara

This whole memory map is somewhat of a legacy. Apart from a few addresses for the SPL needs we shouldn't have those defines at all. Some symbols are needed because there are other macros using them, although these then are eventually unused.
I have some patches to remove most of the symbols, and patch 14/17 demonstrates some idea how to pin this down to what's really needed.

For this particular case: this was copied from the H6 memory map, some addresses are just plain wrong for the D1 family. I will try to remove them as much as possible, leaving only the ones needed in.

I see - the only "tangible" concern I had was the access to prcm->res_cal_ctrl done in arch/arm/mach-sunxi/clock_sun50i_h6.c:clock_init_safe

This doesn't appear to upset the silicon but also doesn't seem necessary either -- and with how tight of a memory footprint SPL has to fit into, I wanted to check whether this was just something undocumented or dead code that needed to be removed. It sounds like it's mostly the latter.

Quoted 3 lines

So where did you see problems? If you would (wrongly) reference PortL somewhere in SPL GPIO code, it would use a wrong pointer, but at least the code would still compile fine, wouldn't it?

The specific patch I had to apply (to arch/arm/mach-sunxi/board.c) was:

        /* Update PIO power bias configuration by copy hardware 
detected value */
        val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
        writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
-       val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
-       writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+       if (SUNXI_R_PIO_BASE) {

+ val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
+ writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+ }

With SUNXI_R_PIO_BASE being 0, this was actually attempting to write to BROM. This might also be something that doesn't really upset the silicon, though: my debug environment is a concolic emulator I quickly hacked up to trace MMIO accesses, and it flagged the write to BROM as an error. It was easier to patch the SPL than to have the emulator ignore the error (and verify that the T113 was cool with it).

Since this kind of extraneous/erroneous init code tends to remain undetected when the symbols they need are dummied-out like this, I figured I'd give a nudge in the direction of instead *removing* the symbols where appropriate and fixing whatever breaks -- especially since we really need to be thrifty about SPL size. But that might also be something that happens in a later cleanup pass when the patchset is being prepared for upstream inclusion. :)

Quoted 3 lines

P.S. Could you try the github post? Then compiled and booted fine for me, and includes the DRAM code as well now:
https://github.com/apritzel/u-boot/commits/t113s-mq-r-WIP

Ooh, more up-to-date code, thanks for the link! I'll switch to using this instead going forward. My pulls from that branch might be relatively infrequent since I'm also working on some patches for better Clang compatibility concurrent with the efforts here. Is this email thread a good venue for feedback against that branch or would you prefer that I use GitHub issues instead?

Warm regards,
Sam

P.S. My target is the BMC on the Turing Pi 2 board. They have the same SoC and (apparently) UART console configuration, but the differences end there: in particular, my target supports boot from either/both microSD+SPI-NAND. I might have to start pushing for room for SPI drivers in the SPL soon. :)

#19 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

On Tue, 16 May 2023 17:53:38 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 12 lines · Andre Przywara
Quoted 10 lines

This whole memory map is somewhat of a legacy. Apart from a few addresses for the SPL needs we shouldn't have those defines at all. Some symbols are needed because there are other macros using them, although these then are eventually unused.
I have some patches to remove most of the symbols, and patch 14/17 demonstrates some idea how to pin this down to what's really needed.

For this particular case: this was copied from the H6 memory map, some addresses are just plain wrong for the D1 family. I will try to remove them as much as possible, leaving only the ones needed in.

Quoted 6 lines

I see - the only "tangible" concern I had was the access to prcm->res_cal_ctrl done in arch/arm/mach-sunxi/clock_sun50i_h6.c:clock_init_safe

This doesn't appear to upset the silicon but also doesn't seem necessary either -- and with how tight of a memory footprint SPL has to fit into,

What's the particular concern here? Compared to the A64 we are pretty
cool: it's Thumb2 code and we are at around 27KB, at least with my toolchain. And I haven't tried, but I am pretty sure the BROM loads more than 32K, as it does on the H6 and H616 already. The U-Boot build system and the code already supports this - we rely on this for the H616 - so we can lift the limit anytime, if really needed.

Quoted 2 lines

I wanted to check whether this was just something undocumented or dead code that needed to be removed. It sounds like it's mostly the latter.

I haven't checked if the vendor boot0 does this. I am pretty sure there is a PRCM block, it's just regularly not mentioned in the manuals.

Quoted 9 lines
Quoted 3 lines

So where did you see problems? If you would (wrongly) reference PortL somewhere in SPL GPIO code, it would use a wrong pointer, but at least the code would still compile fine, wouldn't it?

The specific patch I had to apply (to arch/arm/mach-sunxi/board.c) was:

         /* Update PIO power bias configuration by copy hardware 
detected value */
         val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
         writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);

Review

Quoted 6 lines
(quoted diff) +4 -2
-       val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
-       writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+       if (SUNXI_R_PIO_BASE) {
+               val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
+               writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+       }

Ah, I see, I indeed missed that. We seem to define all symbols anyway, so we can even lose the #ifdef and use proper if's here. Will incorporate that in the next drop.

Quoted 6 lines

With SUNXI_R_PIO_BASE being 0, this was actually attempting to write to BROM. This might also be something that doesn't really upset the silicon, though: my debug environment is a concolic emulator I quickly hacked up to trace MMIO accesses, and it flagged the write to BROM as an error. It was easier to patch the SPL than to have the emulator ignore the error (and verify that the T113 was cool with it).

Ah yeah, the Allwinner interconnect is pretty relaxed about those
things: accesses to addresses with no device behind them are usually ignored (RAZ/WI), where other platform might throw an external abort. Writes to ROM areas are ignored as well.

Quoted 8 lines

Since this kind of extraneous/erroneous init code tends to remain undetected when the symbols they need are dummied-out like this, I figured I'd give a nudge in the direction of instead *removing* the symbols where appropriate and fixing whatever breaks -- especially since we really need to be thrifty about SPL size. But that might also be something that happens in a later cleanup pass when the patchset is being prepared for upstream inclusion. :)

Quoted 7 lines
Quoted 3 lines

P.S. Could you try the github post? Then compiled and booted fine for me, and includes the DRAM code as well now:
https://github.com/apritzel/u-boot/commits/t113s-mq-r-WIP

Ooh, more up-to-date code, thanks for the link! I'll switch to using this instead going forward. My pulls from that branch might be relatively infrequent

Don't worry, I won't push to this anymore.

Quoted 4 lines

since I'm also working on some patches for better
Clang compatibility concurrent with the efforts here. Is this email thread a good venue for feedback against that branch or would you prefer that I use GitHub issues instead?

Please use this thread here, if you find something still wrong in the branch. I just pushed it to github since someone asked for a fixed and complete version, and I didn't have time to prepare a proper post again.

I will hopefully post a proper version for upstreaming in the next days.

Quoted 4 lines

Warm regards,
Sam

P.S. My target is the BMC on the Turing Pi 2 board.

Ah, interesting, didn't know that this is now a BMC - for a SoC from Allwinner's arch nemesis Rockchip ;-)

Quoted 5 lines

They have the same
SoC and (apparently) UART console configuration, but the differences end
there: in particular, my target supports boot from either/both microSD+SPI-NAND. I might have to start pushing for room for SPI drivers in the SPL soon. :)

We already have SPI(-NOR) booting support, check arch/arm/mach-sunxi/spl_spi_sunxi.c. This code is very small, and just needs to be updated to cover the D1/T113 SPI controller, which is slightly different. See
https://lore.kernel.org/linux-arm-kernel/[email protected]/
for the Linux SPI bits.
Regarding SPI-*NAND*: there is
https://patchwork.ozlabs.org/user/todo/uboot/?series=322733
which is supposed to allow loading U-Boot proper from SPI-NAND. I haven't tested it yet, and wasn't overly happy with the refactoring, but would appreciate any kind of review or test.

Cheers,
Andre

#20 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

On Wed, 17 May 2023 01:43:12 +0100
Andre Przywara <[email protected]> wrote:

+Maksim, as he was interested in the U-Boot series as well and had some plans for SPI-NOR booting, IIUC.

Cheers,
Andre

Quoted 128 lines

On Tue, 16 May 2023 17:53:38 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 12 lines · Andre Przywara
Quoted 10 lines

This whole memory map is somewhat of a legacy. Apart from a few addresses for the SPL needs we shouldn't have those defines at all. Some symbols are needed because there are other macros using them, although these then are eventually unused.
I have some patches to remove most of the symbols, and patch 14/17 demonstrates some idea how to pin this down to what's really needed.

For this particular case: this was copied from the H6 memory map, some addresses are just plain wrong for the D1 family. I will try to remove them as much as possible, leaving only the ones needed in.

Quoted 6 lines

I see - the only "tangible" concern I had was the access to prcm->res_cal_ctrl done in arch/arm/mach-sunxi/clock_sun50i_h6.c:clock_init_safe

This doesn't appear to upset the silicon but also doesn't seem necessary either -- and with how tight of a memory footprint SPL has to fit into,

What's the particular concern here? Compared to the A64 we are pretty
cool: it's Thumb2 code and we are at around 27KB, at least with my toolchain. And I haven't tried, but I am pretty sure the BROM loads more than 32K, as it does on the H6 and H616 already. The U-Boot build system and the code already supports this - we rely on this for the H616 - so we can lift the limit anytime, if really needed.

Quoted 2 lines

I wanted to check whether this was just something undocumented or dead code that needed to be removed. It sounds like it's mostly the latter.

I haven't checked if the vendor boot0 does this. I am pretty sure there is a PRCM block, it's just regularly not mentioned in the manuals.

Quoted 9 lines
Quoted 3 lines

So where did you see problems? If you would (wrongly) reference PortL somewhere in SPL GPIO code, it would use a wrong pointer, but at least the code would still compile fine, wouldn't it?

The specific patch I had to apply (to arch/arm/mach-sunxi/board.c) was:

         /* Update PIO power bias configuration by copy hardware 
detected value */
         val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
         writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);

Review

Quoted 6 lines
(quoted diff) +4 -2
-       val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
-       writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+       if (SUNXI_R_PIO_BASE) {
+               val = readl(SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
+               writel(val, SUNXI_R_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);
+       }  

Ah, I see, I indeed missed that. We seem to define all symbols anyway, so we can even lose the #ifdef and use proper if's here. Will incorporate that in the next drop.

Quoted 6 lines

With SUNXI_R_PIO_BASE being 0, this was actually attempting to write to BROM. This might also be something that doesn't really upset the silicon, though: my debug environment is a concolic emulator I quickly hacked up to trace MMIO accesses, and it flagged the write to BROM as an error. It was easier to patch the SPL than to have the emulator ignore the error (and verify that the T113 was cool with it).

Ah yeah, the Allwinner interconnect is pretty relaxed about those
things: accesses to addresses with no device behind them are usually ignored (RAZ/WI), where other platform might throw an external abort. Writes to ROM areas are ignored as well.

Quoted 8 lines

Since this kind of extraneous/erroneous init code tends to remain undetected when the symbols they need are dummied-out like this, I figured I'd give a nudge in the direction of instead *removing* the symbols where appropriate and fixing whatever breaks -- especially since we really need to be thrifty about SPL size. But that might also be something that happens in a later cleanup pass when the patchset is being prepared for upstream inclusion. :)

Quoted 7 lines
Quoted 3 lines

P.S. Could you try the github post? Then compiled and booted fine for me, and includes the DRAM code as well now:
https://github.com/apritzel/u-boot/commits/t113s-mq-r-WIP

Ooh, more up-to-date code, thanks for the link! I'll switch to using this instead going forward. My pulls from that branch might be relatively infrequent

Don't worry, I won't push to this anymore.

Quoted 4 lines

since I'm also working on some patches for better
Clang compatibility concurrent with the efforts here. Is this email thread a good venue for feedback against that branch or would you prefer that I use GitHub issues instead?

Please use this thread here, if you find something still wrong in the branch. I just pushed it to github since someone asked for a fixed and complete version, and I didn't have time to prepare a proper post again.

I will hopefully post a proper version for upstreaming in the next days.

Quoted 4 lines

Warm regards,
Sam

P.S. My target is the BMC on the Turing Pi 2 board.

Ah, interesting, didn't know that this is now a BMC - for a SoC from Allwinner's arch nemesis Rockchip ;-)

Quoted 5 lines

They have the same
SoC and (apparently) UART console configuration, but the differences end
there: in particular, my target supports boot from either/both microSD+SPI-NAND. I might have to start pushing for room for SPI drivers in the SPL soon. :)

We already have SPI(-NOR) booting support, check arch/arm/mach-sunxi/spl_spi_sunxi.c. This code is very small, and just needs to be updated to cover the D1/T113 SPI controller, which is slightly different. See
https://lore.kernel.org/linux-arm-kernel/[email protected]/
for the Linux SPI bits.
Regarding SPI-*NAND*: there is
https://patchwork.ozlabs.org/user/todo/uboot/?series=322733
which is supposed to allow loading U-Boot proper from SPI-NAND. I haven't tested it yet, and wasn't overly happy with the refactoring, but would appreciate any kind of review or test.

Cheers,
Andre

#21 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

Hi Sam,

Quoted 2 lines

I might have to start pushing for room for SPI drivers in the SPL soon. :)

As Andre already pointed out, I have a patch which adds boot support from SPI-NOR for D1/T113 SoCs.
Maybe I can share it somewhere to avoid double work?

#22 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

Hi, Andre

Could you please include this fix for i2c in the next version of this series.

drivers/i2c/mvtwsi.c +0 -0
index 93bbc6916e..d088ea75b9 100644
@@ -124,7 +124,7 @@ enum mvtwsi_ctrl_register_fields {

  * on other platforms, it is a normal r/w bit, which is cleared by writing 0. */

-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)

 #define        MVTWSI_CONTROL_CLEAR_IFLG       0x00000008 #else
 #define        MVTWSI_CONTROL_CLEAR_IFLG       0x00000000

#23 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

On Thu, 25 May 2023 21:25:57 +0300
Maksim Kiselev <[email protected]> wrote:

Hi Maksim,

Quoted 14 lines

Could you please include this fix for i2c in the next version of this series.

drivers/i2c/mvtwsi.c +0 -0
index 93bbc6916e..d088ea75b9 100644
@@ -124,7 +124,7 @@ enum mvtwsi_ctrl_register_fields {
   * on other platforms, it is a normal r/w bit, which is cleared by 

writing 0.
  */

drivers/i2c/mvtwsi.c +1 -1
-#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#if defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || 
Quoted 1 line

defined(CONFIG_SUNXI_GEN_NCAT2)

Ah, thanks for pointing this out, I never really tried I2C, I think. So those code lines are of course hideous to begin with, but it's a nightmare to fix this properly (by looking at the DT compatible string), and we might need it for the SPL anyway, so would need something like this anyway.
So I will just go ahead and add this to this patch.

Thanks for the report!

Cheers,
Andre

Quoted 4 lines

 #define        MVTWSI_CONTROL_CLEAR_IFLG       0x00000008 #else
 #define        MVTWSI_CONTROL_CLEAR_IFLG       0x00000000

#24 lore raw

Re: [RFC PATCH 08/17] sunxi: introduce NCAT2 generation model

In reply to Andre Przywara

Hi again Andre,

Quoted 14 lines · Andre Przywara
arch/arm/mach-sunxi/board.c +1 -1
index b6ffbff883c..3763ec3d2e4 100644
@@ -177,7 +177,7 @@ static int gpio_init(void)
  #error Unsupported console port number. Please fix pin mux settings in board.c
  #endif
 
-#ifdef CONFIG_SUN50I_GEN_H6
+#if defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
  	/* Update PIO power bias configuration by copy hardware detected value */
  	val = readl(SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_VAL);
  	writel(val, SUNXI_PIO_BASE + SUN50I_H6_GPIO_POW_MOD_SEL);

arch/arm/mach-sunxi/board.c void reset_cpu(void) · line 481

Quoted 8 lines
arch/arm/mach-sunxi/board.c +1 -1
@@ -475,7 +475,7 @@ void reset_cpu(void)
  		/* sun5i sometimes gets stuck without this */
  		writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
  	}
-#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6)
+#elif defined(CONFIG_SUNXI_GEN_SUN6I) || defined(CONFIG_SUN50I_GEN_H6) || defined(CONFIG_SUNXI_GEN_NCAT2)
  #if defined(CONFIG_MACH_SUN50I_H6)
  	/* WDOG is broken for some H6 rev. use the R_WDOG instead */
  	static const struct sunxi_wdog *wdog =

It appears that the R528/T113s updated the watchdog slightly from H6 in that it now requires a key (0x16AA << 16) OR'd in all writes to WDOG_SOFT_RST_REG, WDOG_CFG_REG, and WDOG_MODE_REG, or it will ignore those writes. This reset code busywaits indefinitely unless I add that key. It looks like sunxi_wdt.c needs to be updated as well, but I don't know if that's in-scope for this patchset.

Cheers,
Sam

#25 lore raw

RFC PATCH 9/17 pinctrl: sunxi: add Allwinner D1 pinctrl description

In reply to Andre Przywara

Apart from using the new pinctrl MMIO register layout, the Allwinner D1 and related SoCs still need to usual set of mux values hardcoded in U-Boot's pinctrl driver.
Add the values we need so far to this list, so that DM based drivers will just work without further ado.

---
 drivers/pinctrl/sunxi/Kconfig         |  4 ++++
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 28 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
drivers/pinctrl/sunxi/Kconfig +4 -0
index 77da90836b6..c8f937d91e9 100644
@@ -124,4 +124,8 @@ config PINCTRL_SUN50I_H616_R
 	default MACH_SUN50I_H616
 	select PINCTRL_SUNXI
 
+config PINCTRL_SUN20I_D1
+	bool "Support for the Allwinner D1/R528 PIO"
+	select PINCTRL_SUNXI
+
 endif
drivers/pinctrl/sunxi/pinctrl-sunxi.c +28 -0
index 8c12febcc0d..83720cea747 100644
@@ -728,6 +728,28 @@ static const struct sunxi_pinctrl_desc __maybe_unused sun50i_h616_r_pinctrl_desc
 	.num_banks	= 1,
 };
 
+static const struct sunxi_pinctrl_function sun20i_d1_pinctrl_functions[] = {
+	{ "emac",	8 },	/* PE0-PE15 */
+	{ "gpio_in",	0 },
+	{ "gpio_out",	1 },
+	{ "mmc0",	2 },	/* PF0-PF5 */
+	{ "mmc2",	3 },	/* PC1-PC7 */
+	{ "spi0",	2 },	/* PC2-PC7 */
+#if IS_ENABLED(CONFIG_UART0_PORT_F)
+	{ "uart0",	3 },	/* PF2-PF4 */
+#else
+	{ "uart0",	6 },	/* PB2-PB3 */
+#endif
+	{ "uart3",	3 },	/* PB6-PB9 */
+};
+
+static const struct sunxi_pinctrl_desc __maybe_unused sun20i_d1_pinctrl_desc = {
+	.functions	= sun20i_d1_pinctrl_functions,
+	.num_functions	= ARRAY_SIZE(sun20i_d1_pinctrl_functions),
+	.first_bank	= SUNXI_GPIO_A,
+	.num_banks	= 7,
+};
+
 static const struct udevice_id sunxi_pinctrl_ids[] = {
 #ifdef CONFIG_PINCTRL_SUNIV_F1C100S
 	{
@@ -884,6 +906,12 @@ static const struct udevice_id sunxi_pinctrl_ids[] = {
 		.compatible = "allwinner,sun50i-h616-r-pinctrl",
 		.data = (ulong)&sun50i_h616_r_pinctrl_desc,
 	},
+#endif
+#ifdef CONFIG_PINCTRL_SUN20I_D1
+	{
+		.compatible = "allwinner,sun20i-d1-pinctrl",
+		.data = (ulong)&sun20i_d1_pinctrl_desc,
+	},
 #endif
 	{}
 };
Signature · 1 line
2.35.5
#26 lore raw

RFC PATCH 10/17 clk: sunxi: Add support for the D1 CCU

In reply to Andre Przywara

From: Samuel Holland <[email protected]>

Since the D1 CCU binding is defined, we can add support for its gates/resets, following the pattern of the existing drivers.

---
 drivers/clk/sunxi/Kconfig                 |   6 +
 drivers/clk/sunxi/Makefile                |   1 +
 drivers/clk/sunxi/clk_d1.c                | 101 ++++++++++++++
 include/dt-bindings/clock/sun20i-d1-ccu.h | 156 ++++++++++++++++++++++
 include/dt-bindings/reset/sun20i-d1-ccu.h |  77 +++++++++++
 5 files changed, 341 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk_d1.c
 create mode 100644 include/dt-bindings/clock/sun20i-d1-ccu.h
 create mode 100644 include/dt-bindings/reset/sun20i-d1-ccu.h
drivers/clk/sunxi/Kconfig +6 -0
index bf11fad6eef..f65e482ba4c 100644
@@ -87,6 +87,12 @@ config CLK_SUN8I_H3
 	  This enables common clock driver support for platforms based
 	  on Allwinner H3/H5 SoC.
 
+config CLK_SUN20I_D1
+	bool "Clock driver for Allwinner D1"
+	help
+	  This enables common clock driver support for platforms based
+	  on Allwinner D1 SoC.
+
 config CLK_SUN50I_H6
 	bool "Clock driver for Allwinner H6"
 	default MACH_SUN50I_H6
drivers/clk/sunxi/Makefile +1 -0
index 895da02ebea..90a277489dc 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_CLK_SUN8I_R40) += clk_r40.o
 obj-$(CONFIG_CLK_SUN8I_V3S) += clk_v3s.o
 obj-$(CONFIG_CLK_SUN9I_A80) += clk_a80.o
 obj-$(CONFIG_CLK_SUN8I_H3) += clk_h3.o
+obj-$(CONFIG_CLK_SUN20I_D1) += clk_d1.o
 obj-$(CONFIG_CLK_SUN50I_H6) += clk_h6.o
 obj-$(CONFIG_CLK_SUN50I_H6_R) += clk_h6_r.o
 obj-$(CONFIG_CLK_SUN50I_H616) += clk_h616.o
drivers/clk/sunxi/clk_d1.c new file +101 -0

101 lines not on this page · raw message

include/dt-bindings/clock/sun20i-d1-ccu.h new file +156 -0

156 lines not on this page · raw message

include/dt-bindings/reset/sun20i-d1-ccu.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.35.5
#27 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

Quoted 8 lines · Andre Przywara

From: Samuel Holland <[email protected]>

Since the D1 CCU binding is defined, we can add support for its gates/resets, following the pattern of the existing drivers.

Hi Andre,

So far so good! This patchset seems pretty functional. I'm still trying to get various peripherals on my board up and running; there are a couple of rough edges I'm encountering. I'll report back when I have a build I like.

In particular, I had to update this patch in your series to be consistent with 46fa23f9ee. My own patch follows.

I'd also suggest adding to mangopi_mq_r_defconfig:
CONFIG_CLK_SUN20I_D1=y
...or, better yet, an appropriate select in Kconfig?

Cheers,
Sam

--

drivers/clk/sunxi/clk_d1.c +3 -22
index 9412b77a54..f4ff682566 100644
@@ -74,28 +74,9 @@ static struct ccu_reset d1_resets[] = {
 	[RST_BUS_LRADC]		= RESET(0xa9c, BIT(16)),
 };
 
-static const struct ccu_desc d1_ccu_desc = {
+const struct ccu_desc d1_ccu_desc = {
 	.gates	= d1_gates,
 	.resets	= d1_resets,
-};
-
-static int d1_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(d1_resets));
-}
-
-static const struct udevice_id d1_ccu_ids[] = {
-	{ .compatible = "allwinner,sun20i-d1-ccu",
-	  .data = (ulong)&d1_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun20i_d1) = {
-	.name		= "sun20i_d1_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= d1_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= d1_clk_bind,
+	.num_gates  = ARRAY_SIZE(d1_gates),
+	.num_resets = ARRAY_SIZE(d1_resets),
 };
drivers/clk/sunxi/clk_sunxi.c +5 -0
index ec02a2d037..176d3cbc28 100644
@@ -125,6 +125,7 @@ extern const struct ccu_desc h616_ccu_desc;
 extern const struct ccu_desc h6_r_ccu_desc;
 extern const struct ccu_desc r40_ccu_desc;
 extern const struct ccu_desc v3s_ccu_desc;
+extern const struct ccu_desc d1_ccu_desc;
 
 static const struct udevice_id sunxi_clk_ids[] = {
 #ifdef CONFIG_CLK_SUN4I_A10
@@ -214,6 +215,10 @@ static const struct udevice_id sunxi_clk_ids[] = {
 #ifdef CONFIG_CLK_SUNIV_F1C100S
 	{ .compatible = "allwinner,suniv-f1c100s-ccu",
 	  .data = (ulong)&f1c100s_ccu_desc },
+#endif
+#ifdef CONFIG_CLK_SUN20I_D1
+	{ .compatible = "allwinner,sun20i-d1-ccu",
+	  .data = (ulong)&d1_ccu_desc },
 #endif
 	{ }
 };
author Applied
#28 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

On Sun, 21 May 2023 21:57:57 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 12 lines · Andre Przywara
Quoted 8 lines

From: Samuel Holland <[email protected]>

Since the D1 CCU binding is defined, we can add support for its gates/resets, following the pattern of the existing drivers.

Hi Andre,

Quoted 7 lines

So far so good! This patchset seems pretty functional. I'm still trying to get various peripherals on my board up and running; there are a couple of rough edges I'm encountering. I'll report back when I have a build I like.

In particular, I had to update this patch in your series to be consistent with 46fa23f9ee. My own patch follows.

Ah, yeah, Samuel's rework. Thanks for the heads up, I somehow missed that when updating the series!

Quoted 3 lines

I'd also suggest adding to mangopi_mq_r_defconfig:
CONFIG_CLK_SUN20I_D1=y
...or, better yet, an appropriate select in Kconfig?

I think this is related to the rework, I just added a "default MACH_SUN8I_R528" line to the clock's Kconfig, similar to what we already do for the pinctrl driver.

I merged the changes into the respective patch.

Please note that I also found a build bug for 64-bit SoCs, and that the new DRAM driver's Kconfig symbols conflict with the already used symbols for other DRAM drivers (like the A64 one). This broke the A64 DRAM init routine, for instance.

If the tests work well, I will try to post some proper version ASAP. If not, I will probably just push some updated WIP version to my Github.

Thanks,
Andre

Quoted 61 lines

--

drivers/clk/sunxi/clk_d1.c +3 -22
index 9412b77a54..f4ff682566 100644
@@ -74,28 +74,9 @@ static struct ccu_reset d1_resets[] = {
  	[RST_BUS_LRADC]		= RESET(0xa9c, BIT(16)),
  };
 
-static const struct ccu_desc d1_ccu_desc = {
+const struct ccu_desc d1_ccu_desc = {
  	.gates	= d1_gates,
  	.resets	= d1_resets,
-};
-
-static int d1_clk_bind(struct udevice *dev)
-{
-	return sunxi_reset_bind(dev, ARRAY_SIZE(d1_resets));
-}
-
-static const struct udevice_id d1_ccu_ids[] = {
-	{ .compatible = "allwinner,sun20i-d1-ccu",
-	  .data = (ulong)&d1_ccu_desc },
-	{ }
-};
-
-U_BOOT_DRIVER(clk_sun20i_d1) = {
-	.name		= "sun20i_d1_ccu",
-	.id		= UCLASS_CLK,
-	.of_match	= d1_ccu_ids,
-	.priv_auto	= sizeof(struct ccu_priv),
-	.ops		= &sunxi_clk_ops,
-	.probe		= sunxi_clk_probe,
-	.bind		= d1_clk_bind,
+	.num_gates  = ARRAY_SIZE(d1_gates),
+	.num_resets = ARRAY_SIZE(d1_resets),
  };
(quoted diff) +0 -0

b/drivers/clk/sunxi/clk_sunxi.c index ec02a2d037..176d3cbc28 100644

drivers/clk/sunxi/clk_sunxi.c +1 -0
@@ -125,6 +125,7 @@ extern const struct ccu_desc h616_ccu_desc;
  extern const struct ccu_desc h6_r_ccu_desc;
  extern const struct ccu_desc r40_ccu_desc;
  extern const struct ccu_desc v3s_ccu_desc;
+extern const struct ccu_desc d1_ccu_desc;
 
  static const struct udevice_id sunxi_clk_ids[] = {
  #ifdef CONFIG_CLK_SUN4I_A10
@@ -214,6 +215,10 @@ static const struct udevice_id sunxi_clk_ids[] =

{ #ifdef CONFIG_CLK_SUNIV_F1C100S
{ .compatible = "allwinner,suniv-f1c100s-ccu",
.data = (ulong)&f1c100s_ccu_desc },

drivers/clk/sunxi/clk_sunxi.c +4 -0
+#endif
+#ifdef CONFIG_CLK_SUN20I_D1
+	{ .compatible = "allwinner,sun20i-d1-ccu",
+	  .data = (ulong)&d1_ccu_desc },
  #endif
  	{ }
  };
#29 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

In reply to Andre Przywara

Hi again Andre,

Quoted 22 lines · Andre Przywara
drivers/clk/sunxi/clk_d1.c new file +22 -0
+static struct ccu_clk_gate d1_gates[] = {
+	[CLK_BUS_MMC0]		= GATE(0x84c, BIT(0)),
+	[CLK_BUS_MMC1]		= GATE(0x84c, BIT(1)),
+	[CLK_BUS_MMC2]		= GATE(0x84c, BIT(2)),
+	[CLK_BUS_UART0]		= GATE(0x90c, BIT(0)),
+	[CLK_BUS_UART1]		= GATE(0x90c, BIT(1)),
+	[CLK_BUS_UART2]		= GATE(0x90c, BIT(2)),
+	[CLK_BUS_UART3]		= GATE(0x90c, BIT(3)),
+	[CLK_BUS_UART4]		= GATE(0x90c, BIT(4)),
+	[CLK_BUS_UART5]		= GATE(0x90c, BIT(5)),
+	[CLK_BUS_I2C0]		= GATE(0x91c, BIT(0)),
+	[CLK_BUS_I2C1]		= GATE(0x91c, BIT(1)),
+	[CLK_BUS_I2C2]		= GATE(0x91c, BIT(2)),
+	[CLK_BUS_I2C3]		= GATE(0x91c, BIT(3)),
+	[CLK_SPI0]		= GATE(0x940, BIT(31)),
+	[CLK_SPI1]		= GATE(0x944, BIT(31)),
+	[CLK_BUS_SPI0]		= GATE(0x96c, BIT(0)),
+	[CLK_BUS_SPI1]		= GATE(0x96c, BIT(1)),
+
+	[CLK_BUS_EMAC]		= GATE(0x97c, BIT(0)),
+
+	[CLK_USB_OHCI0]		= GATE(0xa70, BIT(31)),

drivers/clk/sunxi/clk_d1.c line 46

Quoted 10 lines
drivers/clk/sunxi/clk_d1.c new file +10 -0
+	[CLK_USB_OHCI1]		= GATE(0xa74, BIT(31)),
+	[CLK_BUS_OHCI0]		= GATE(0xa8c, BIT(0)),
+	[CLK_BUS_OHCI1]		= GATE(0xa8c, BIT(1)),
+	[CLK_BUS_EHCI0]		= GATE(0xa8c, BIT(4)),
+	[CLK_BUS_EHCI1]		= GATE(0xa8c, BIT(5)),
+	[CLK_BUS_OTG]		= GATE(0xa8c, BIT(8)),
+	[CLK_BUS_LRADC]		= GATE(0xa9c, BIT(0)),
+
+	[CLK_RISCV]		= GATE(0xd04, BIT(31)),
+};

Would it be reasonable to add (possibly one for APB1 also):
[CLK_APB0] = GATE_DUMMY,

...in order to suppress this warning at init:
sunxi_set_gate: (CLK#24) unhandled

As I understand it, CLK_APB0 is only for speed control and doesn't have a gate, but since the FDT references it, other drivers are asking the clock driver to ungate it, resulting in that (safe-to-ignore) warning.

Warm regards,
Sam

PS: Do you have any plans for PSCI support, so we can get the second core up too? I'd like to patch that in and include it in your series once my available time permits. Just thought I'd check that you/someone wasn't working on it already. :)

#30 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

On Thu, 25 May 2023 18:34:45 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

thanks for staying on this!

Quoted 37 lines · Andre Przywara
Quoted 22 lines
drivers/clk/sunxi/clk_d1.c new file +22 -0
+static struct ccu_clk_gate d1_gates[] = {
+	[CLK_BUS_MMC0]		= GATE(0x84c, BIT(0)),
+	[CLK_BUS_MMC1]		= GATE(0x84c, BIT(1)),
+	[CLK_BUS_MMC2]		= GATE(0x84c, BIT(2)),
+	[CLK_BUS_UART0]		= GATE(0x90c, BIT(0)),
+	[CLK_BUS_UART1]		= GATE(0x90c, BIT(1)),
+	[CLK_BUS_UART2]		= GATE(0x90c, BIT(2)),
+	[CLK_BUS_UART3]		= GATE(0x90c, BIT(3)),
+	[CLK_BUS_UART4]		= GATE(0x90c, BIT(4)),
+	[CLK_BUS_UART5]		= GATE(0x90c, BIT(5)),
+	[CLK_BUS_I2C0]		= GATE(0x91c, BIT(0)),
+	[CLK_BUS_I2C1]		= GATE(0x91c, BIT(1)),
+	[CLK_BUS_I2C2]		= GATE(0x91c, BIT(2)),
+	[CLK_BUS_I2C3]		= GATE(0x91c, BIT(3)),
+	[CLK_SPI0]		= GATE(0x940, BIT(31)),
+	[CLK_SPI1]		= GATE(0x944, BIT(31)),
+	[CLK_BUS_SPI0]		= GATE(0x96c, BIT(0)),
+	[CLK_BUS_SPI1]		= GATE(0x96c, BIT(1)),
+
+	[CLK_BUS_EMAC]		= GATE(0x97c, BIT(0)),
+
+	[CLK_USB_OHCI0]		= GATE(0xa70, BIT(31)),

drivers/clk/sunxi/clk_d1.c line 46

Quoted 10 lines
drivers/clk/sunxi/clk_d1.c new file +10 -0
+	[CLK_USB_OHCI1]		= GATE(0xa74, BIT(31)),
+	[CLK_BUS_OHCI0]		= GATE(0xa8c, BIT(0)),
+	[CLK_BUS_OHCI1]		= GATE(0xa8c, BIT(1)),
+	[CLK_BUS_EHCI0]		= GATE(0xa8c, BIT(4)),
+	[CLK_BUS_EHCI1]		= GATE(0xa8c, BIT(5)),
+	[CLK_BUS_OTG]		= GATE(0xa8c, BIT(8)),
+	[CLK_BUS_LRADC]		= GATE(0xa9c, BIT(0)),
+
+	[CLK_RISCV]		= GATE(0xd04, BIT(31)),
+};  

Would it be reasonable to add (possibly one for APB1 also):
[CLK_APB0] = GATE_DUMMY,

Quoted 2 lines

...in order to suppress this warning at init:
sunxi_set_gate: (CLK#24) unhandled

Yeah, seems like we are working in lockstep, as I found and fixed the very same issue in the very same way on Wednesday ;-)

Quoted 3 lines

As I understand it, CLK_APB0 is only for speed control and doesn't have a gate, but since the FDT references it, other drivers are asking the clock driver to ungate it, resulting in that (safe-to-ignore) warning.

The APB0 bus transports register accesses to a certain subset of "low speed" peripherals, Those peripherals include the clock control unit (CCU) itself, and the GPIO registers, so it's quite essential for normal operation. CLK_APB0 is the clock driving that bus, and as it's controlled via the CCU, you just cannot turn that off. Check "Figure 3-3 System bus tree" in the manual.

Linux never really touches that clock (for said reasons), and Allwinner recommends a certain frequency, which we set up in the SPL.

So to not boil the ocean here for something that doesn't need control anyway, we just introduced those "dummy gates", to appease U-Boot's clock framework and avoid that warning.

Long story short: you did everything right ;-)

Quoted 4 lines

PS: Do you have any plans for PSCI support, so we can get the second core up too? I'd like to patch that in and include it in your series once my available time permits. Just thought I'd check that you/someone wasn't working on it already. :)

I checked the manuals, and it seems the required bits are documented, but IIRC they differ from the other (much older) 32-bit parts. So it would require some refactoring of the existing sunxi PSCI code to accommodate the T113.
That's not really a problem, but I didn't find time yet to tackle this, so if you want to beat me on it: be my guest.
For the basic operation SMP is not essential, so I don't want to let that hold back the T113 U-Boot support in general. The plan is to have an extra patch on top for PSCI, and merge that when it's ready - which could be together with the basic support, if we get it done on time.

Cheers,
Andre

#31 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

Hi Sam, Andre,

Quoted 4 lines · On Thu, 25 May 2023 18:34:45 -0600 Sam Edwards <[email protected]> wrote:

PS: Do you have any plans for PSCI support, so we can get the second core up too? I'd like to patch that in and include it in your series once my available time permits. Just thought I'd check that you/someone wasn't working on it already. :)

Let me join the PSCI discussion. This is not news, but maybe someone else didn't know it :)

There is a Linux patch that allows to bring up the second core.
https://github.com/szemzoa/awboot/blob/6ea4ae4ad7a558ad952fefee1942e260aea1a69f/linux/second_core_support_in_platsmp.patch#L10

I think this could be useful for adding PSCI support for T113.

Quoted 4 lines · Andre Przywara

I checked the manuals, and it seems the required bits are documented, but IIRC they differ from the other (much older) 32-bit parts. So it would require some refactoring of the existing sunxi PSCI code to accommodate the T113.

For some reason, these registers 0x070005C0, 0x070005C4, 0x070005C8 do not have a detailed description in the user manual. Only there are some notes in the paragraph '3.4.2.3 NON_CPU0 Boot Process' .

#32 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

Hi folks,

Quoted 5 lines · Maksim Kiselev

There is a Linux patch that allows to bring up the second core.
https://github.com/szemzoa/awboot/blob/6ea4ae4ad7a558ad952fefee1942e260aea1a69f/linux/second_core_support_in_platsmp.patch#L10

I think this could be useful for adding PSCI support for T113.

I'm a little surprised that apparently all that is necessary is to set the entry point and deassert reset. I've been trying essentially that so far with no success (entirely possible I made a mistake somewhere). Perhaps this patch assumes that power to the core is enabled before kernel boot? I haven't yet figured out what in the PRCM I need to poke to get power to the core, and the PRCM for this chip is not well-documented.

Quoted 4 lines · Andre Przywara

I checked the manuals, and it seems the required bits are documented, but IIRC they differ from the other (much older) 32-bit parts. So it would require some refactoring of the existing sunxi PSCI code to accommodate the T113.

Yeah, I decided to factor out the register-manipulating bits to a handful of sunxi_cpu_set_* functions, which can be switched out to suit the specific SoC in use. psci.c is growing way too many #ifdef branches, so I might refactor this yet again to the "weak symbols with strong overrides in e.g. psci-r528.c" pattern, unless you find that pattern particularly distasteful.

I have my WIP diff below. Before inclusion, I'll split it into multiple patches (refactoring -> adding R528 support) but it's definitely not ready for that yet. However if you could, it would help if you checked my changes to cpu_sunxi_ncat2.h and squashed them into your own series if they look good to you.

Cheers,
Sam

---

arch/arm/cpu/armv7/sunxi/psci.c +89 -17
index e1d3638b5c..02c5c56c86 100644
@@ -38,6 +38,8 @@
 #define SUN8I_R40_PWR_CLAMP(cpu)		(0x120 + (cpu) * 0x4)
 #define SUN8I_R40_SRAMC_SOFT_ENTRY_REG0		(0xbc)
 
+#define SUN8I_R528_SOFT_ENTRY			(0x1c8)
+
 static void __secure cp15_write_cntp_tval(u32 tval)
 {
 	asm volatile ("mcr p15, 0, %0, c14, c2, 0" : : "r" (tval));
@@ -125,6 +127,13 @@ static void __secure sunxi_set_entry_address(void *entry)
 	writel((u32)entry,
 	       SUNXI_SRAMC_BASE + SUN8I_R40_SRAMC_SOFT_ENTRY_REG0);
 }
+#elif defined CONFIG_MACH_SUN8I_R528
+/* secondary core entry address is programmed differently on R528 */
+static void __secure sunxi_set_entry_address(void *entry)
+{
+	writel((u32)entry,
+	       SUNXI_R_CPUCFG_BASE + SUN8I_R528_SOFT_ENTRY);
+}
 #else
 static void __secure sunxi_set_entry_address(void *entry)
 {
@@ -155,6 +164,10 @@ static void __secure sunxi_cpu_set_power(int cpu, bool on)
 			   (void *)cpucfg + SUN8I_R40_PWROFF,
 			   on, cpu);
 }
+#elif defined CONFIG_MACH_SUN8I_R528
+static void __secure sunxi_cpu_set_power(int __always_unused cpu, bool __always_unused on)
+{
+}
 #else /* ! CONFIG_MACH_SUN7I && ! CONFIG_MACH_SUN8I_R40 */
 static void __secure sunxi_cpu_set_power(int cpu, bool on)
 {
@@ -166,30 +179,91 @@ static void __secure sunxi_cpu_set_power(int cpu, bool on)
 }
 #endif /* CONFIG_MACH_SUN7I */
 
-void __secure sunxi_cpu_power_off(u32 cpuid)
+#ifdef CONFIG_MACH_SUN8I_R528
+#define C0_RST_CTRL	0x0000
+#define C0_CTRL_REG0	0x0010
+#define C0_CPU_STATUS	0x0080
+
+#define C0_BIT_WFI	16
+
+static void __secure sunxi_cpu_set_reset(int cpu, bool active)
+{
+	if (active)
+		clrbits_le32(SUNXI_CPUX_BASE + C0_RST_CTRL, BIT(cpu));
+	else
+		setbits_le32(SUNXI_CPUX_BASE + C0_RST_CTRL, BIT(cpu));
+}
+
+static void __secure sunxi_cpu_set_locking(int cpu, bool lock)
+{
+	/* TODO: I don't know what this is or how to do it */
+}
+
+static bool __secure sunxi_cpu_poll_wfi(int cpu)
+{
+	return !!(readl(SUNXI_CPUX_BASE + C0_CPU_STATUS) & BIT(C0_BIT_WFI + cpu));
+}
+
+static void __secure sunxi_cpu_invalidate_cache(int cpu)
+{
+	clrbits_le32(SUNXI_CPUX_BASE + C0_CTRL_REG0, BIT(cpu));
+}
+#else /* ! CONFIG_MACH_SUN8I_R528 */
+static void __secure sunxi_cpu_set_reset(int cpu, bool active)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	writel(active ? 0b00 : 0b11, &cpucfg->cpu[cpu].rst);
+}
+
+static void __secure sunxi_cpu_set_locking(int cpu, bool lock)
 {
 	struct sunxi_cpucfg_reg *cpucfg =
 		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	if (lock)
+		clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	else
+		setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+}
+
+static bool __secure sunxi_cpu_poll_wfi(int cpu)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	return !!(readl(&cpucfg->cpu[cpu].status) & BIT(2));
+}
+
+static void __secure sunxi_cpu_invalidate_cache(int cpu)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
+}
+#endif
+
+void __secure sunxi_cpu_power_off(u32 cpuid)
+{
 	u32 cpu = cpuid & 0x3;
 
 	/* Wait for the core to enter WFI */
-	while (1) {
-		if (readl(&cpucfg->cpu[cpu].status) & BIT(2))
-			break;
+	while (!sunxi_cpu_poll_wfi(cpu))
 		__mdelay(1);
-	}
 
 	/* Assert reset on target CPU */
-	writel(0, &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, true);
 
 	/* Lock CPU (Disable external debug access) */
-	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	sunxi_cpu_set_locking(cpu, true);
 
 	/* Power down CPU */
 	sunxi_cpu_set_power(cpuid, false);
 
-	/* Unlock CPU (Disable external debug access) */
-	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	/* Unlock CPU (Reenable external debug access) */
+	sunxi_cpu_set_locking(cpu, false);
 }
 
 static u32 __secure cp15_read_scr(void)
@@ -246,8 +320,6 @@ out:
 int __secure psci_cpu_on(u32 __always_unused unused, u32 mpidr, u32 pc,
 			 u32 context_id)
 {
-	struct sunxi_cpucfg_reg *cpucfg =
-		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
 	u32 cpu = (mpidr & 0x3);
 
 	/* store target PC and context id */
@@ -257,22 +329,22 @@ int __secure psci_cpu_on(u32 __always_unused unused, u32 mpidr, u32 pc,
 	sunxi_set_entry_address(&psci_cpu_entry);
 
 	/* Assert reset on target CPU */
-	writel(0, &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, true);
 
 	/* Invalidate L1 cache */
-	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
+	sunxi_cpu_invalidate_cache(cpu);
 
 	/* Lock CPU (Disable external debug access) */
-	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	sunxi_cpu_set_locking(cpu, true);
 
 	/* Power up target CPU */
 	sunxi_cpu_set_power(cpu, true);
 
 	/* De-assert reset on target CPU */
-	writel(BIT(1) | BIT(0), &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, false);
 
-	/* Unlock CPU (Disable external debug access) */
-	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	/* Unlock CPU (Reenable external debug access) */
+	sunxi_cpu_set_locking(cpu, false);
 
 	return ARM_PSCI_RET_SUCCESS;
 }
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h +4 -2
index d01508517c..629d761aa6 100644
@@ -17,6 +17,8 @@
 #define SUNXI_SIDC_BASE			0x03006000
 #define SUNXI_SID_BASE			0x03006200
 #define SUNXI_TIMER_BASE		0x02050000
+#define SUNXI_GIC400_BASE		0x03020000
+#define SUNXI_CPUX_BASE			0x09010000
 
 #ifdef CONFIG_MACH_SUN50I_H6
 #define SUNXI_DRAM_COM_BASE		0x04002000
@@ -34,11 +36,11 @@
 #define SUNXI_SPI0_BASE			0x04025000
 #define SUNXI_SPI1_BASE			0x04026000
 
-#define SUNXI_RTC_BASE			0x07000000
 #define SUNXI_R_CPUCFG_BASE		0x07000400
 #define SUNXI_PRCM_BASE			0x07010000
 #define SUNXI_R_WDOG_BASE		0x07020400
-#define SUNXI_R_TWI_BASE		0x07081400
+#define SUNXI_R_TWI_BASE		0x07020800
+#define SUNXI_RTC_BASE			0x07090000
 
 #ifndef __ASSEMBLY__
 void sunxi_board_init(void);
arch/arm/mach-sunxi/Kconfig +2 -0
index bb9b863d2c..a5d312d377 100644
@@ -366,6 +366,8 @@ config MACH_SUN8I_R40
 config MACH_SUN8I_R528
 	bool "sun8i (Allwinner R528)"
 	select CPU_V7A
+	select CPU_V7_HAS_NONSEC
+	select ARCH_SUPPORT_PSCI
 	select SUNXI_GEN_NCAT2
 	select SUNXI_NEW_PINCTRL
 	select MMC_SUNXI_HAS_NEW_MODE
#33 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

On Fri, 26 May 2023 14:22:29 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 10 lines · Maksim Kiselev
Quoted 5 lines

There is a Linux patch that allows to bring up the second core.
https://github.com/szemzoa/awboot/blob/6ea4ae4ad7a558ad952fefee1942e260aea1a69f/linux/second_core_support_in_platsmp.patch#L10

I think this could be useful for adding PSCI support for T113.

I'm a little surprised that apparently all that is necessary is to set the entry point and deassert reset. I've been trying essentially that so far with no success (entirely possible I made a mistake somewhere).

So with "no success" you are referring to the patch below? Which is the Linux patch ported to U-Boot? And does that mean that the Linux patch works, but the U-Boot version doesn't?

Quoted 3 lines

Perhaps this patch assumes that power to the core is enabled before kernel boot? I haven't yet figured out what in the PRCM I need to poke to get power to the core, and the PRCM for this chip is not well-documented.

The PRCM is routinely not documented in the user manuals, IIUC Allwinner provides separate documents for that (but not to us). So far this was all reverse engineered from either BSP code or some disassembly. Is there any indication in the BSP source code as to how this is supposed to work? And maybe there is no separate power control for the second core?

And have you checked that the PSCI runtime code is correctly hooked up in U-Boot? I have to check what's really needed, but the whole code needs to be linked to secure SRAM, IIRC.

Quoted 6 lines · Andre Przywara
Quoted 4 lines

I checked the manuals, and it seems the required bits are documented, but IIRC they differ from the other (much older) 32-bit parts. So it would require some refactoring of the existing sunxi PSCI code to accommodate the T113.

Quoted 6 lines

Yeah, I decided to factor out the register-manipulating bits to a handful of sunxi_cpu_set_* functions, which can be switched out to suit the specific SoC in use. psci.c is growing way too many #ifdef branches, so I might refactor this yet again to the "weak symbols with strong overrides in e.g. psci-r528.c" pattern, unless you find that pattern particularly distasteful.

We don't need #ifdef's, you can use normal C "if" statements:

static void __secure sunxi_set_entry_address(void *entry)

{
	if (IS_ENABLED(CONFIG_MACH_SUN8I_R528))
		writel((u32)entry,
			SUNXI_R_CPUCFG_BASE + SUN8I_R528_SOFT_ENTRY);
	else 
		writel((u32)entry,
			SUNXI_SRAMC_BASE + SUN8I_R40_SRAMC_SOFT_ENTRY_REG0);
}

"Dead code elimination" in modern compilers will remove everything that's not needed, if this can be figured out at compile time (try it!).

This just requires to have all symbols defined all the time, but there is no reason to protect #define's with #ifdef's either, as it doesn't hurt to have unused preprocessor symbols. Or you define shared names (SUNXI_ENTRY_ADDRESS_BASE), depending on Kconfig symbols. arch/arm/mach-sunxi/spl_spi_sunxi.c makes use of those techniques extensively, have a look there for inspiration (like static functions to return base addresses: spi0_base_address(), this will be optimised away completely).

Quoted 5 lines

I have my WIP diff below. Before inclusion, I'll split it into multiple patches (refactoring -> adding R528 support) but it's definitely not ready for that yet. However if you could, it would help if you checked my changes to cpu_sunxi_ncat2.h and squashed them into your own series if they look good to you.

Sure. I actually removed most of the symbols there, as we don't need them, but can surely add the ones you found for PSCI. Do you need I2C in the SPL (looking at SUNXI_R_TWI_BASE)?

Thanks,
Andre

Quoted 225 lines

---

arch/arm/cpu/armv7/sunxi/psci.c +9 -0
index e1d3638b5c..02c5c56c86 100644
@@ -38,6 +38,8 @@
  #define SUN8I_R40_PWR_CLAMP(cpu)		(0x120 + (cpu) * 0x4)
  #define SUN8I_R40_SRAMC_SOFT_ENTRY_REG0		(0xbc)
 
+#define SUN8I_R528_SOFT_ENTRY			(0x1c8)
+
  static void __secure cp15_write_cntp_tval(u32 tval)
  {
  	asm volatile ("mcr p15, 0, %0, c14, c2, 0" : : "r" (tval));
@@ -125,6 +127,13 @@ static void __secure sunxi_set_entry_address(void 
 *entry)
  	writel((u32)entry,
  	       SUNXI_SRAMC_BASE + SUN8I_R40_SRAMC_SOFT_ENTRY_REG0);
  }
+#elif defined CONFIG_MACH_SUN8I_R528
+/* secondary core entry address is programmed differently on R528 */
+static void __secure sunxi_set_entry_address(void *entry)
+{
+	writel((u32)entry,
+	       SUNXI_R_CPUCFG_BASE + SUN8I_R528_SOFT_ENTRY);
+}
  #else
  static void __secure sunxi_set_entry_address(void *entry)
  {
arch/arm/cpu/armv7/sunxi/psci.c +4 -0
@@ -155,6 +164,10 @@ static void __secure sunxi_cpu_set_power(int cpu, 
 bool on)
  			   (void *)cpucfg + SUN8I_R40_PWROFF,
  			   on, cpu);
  }
+#elif defined CONFIG_MACH_SUN8I_R528
+static void __secure sunxi_cpu_set_power(int __always_unused cpu, bool 
 __always_unused on)
+{
+}
  #else /* ! CONFIG_MACH_SUN7I && ! CONFIG_MACH_SUN8I_R40 */

static void __secure sunxi_cpu_set_power(int cpu, bool on) {

arch/arm/cpu/armv7/sunxi/psci.c +70 -9
@@ -166,30 +179,91 @@ static void __secure sunxi_cpu_set_power(int cpu, 
 bool on)
  }
  #endif /* CONFIG_MACH_SUN7I */
 
-void __secure sunxi_cpu_power_off(u32 cpuid)
+#ifdef CONFIG_MACH_SUN8I_R528
+#define C0_RST_CTRL	0x0000
+#define C0_CTRL_REG0	0x0010
+#define C0_CPU_STATUS	0x0080
+
+#define C0_BIT_WFI	16
+
+static void __secure sunxi_cpu_set_reset(int cpu, bool active)
+{
+	if (active)
+		clrbits_le32(SUNXI_CPUX_BASE + C0_RST_CTRL, BIT(cpu));
+	else
+		setbits_le32(SUNXI_CPUX_BASE + C0_RST_CTRL, BIT(cpu));
+}
+
+static void __secure sunxi_cpu_set_locking(int cpu, bool lock)
+{
+	/* TODO: I don't know what this is or how to do it */
+}
+
+static bool __secure sunxi_cpu_poll_wfi(int cpu)
+{
+	return !!(readl(SUNXI_CPUX_BASE + C0_CPU_STATUS) & BIT(C0_BIT_WFI + cpu));
+}
+
+static void __secure sunxi_cpu_invalidate_cache(int cpu)
+{
+	clrbits_le32(SUNXI_CPUX_BASE + C0_CTRL_REG0, BIT(cpu));
+}
+#else /* ! CONFIG_MACH_SUN8I_R528 */
+static void __secure sunxi_cpu_set_reset(int cpu, bool active)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	writel(active ? 0b00 : 0b11, &cpucfg->cpu[cpu].rst);
+}
+
+static void __secure sunxi_cpu_set_locking(int cpu, bool lock)
  {
  	struct sunxi_cpucfg_reg *cpucfg =
  		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	if (lock)
+		clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	else
+		setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+}
+
+static bool __secure sunxi_cpu_poll_wfi(int cpu)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	return !!(readl(&cpucfg->cpu[cpu].status) & BIT(2));
+}
+
+static void __secure sunxi_cpu_invalidate_cache(int cpu)
+{
+	struct sunxi_cpucfg_reg *cpucfg =
+		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
+
+	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
+}
+#endif
+
+void __secure sunxi_cpu_power_off(u32 cpuid)
+{
  	u32 cpu = cpuid & 0x3;
 
  	/* Wait for the core to enter WFI */
-	while (1) {
-		if (readl(&cpucfg->cpu[cpu].status) & BIT(2))
-			break;
+	while (!sunxi_cpu_poll_wfi(cpu))
  		__mdelay(1);
-	}
 
  	/* Assert reset on target CPU */
-	writel(0, &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, true);
 
  	/* Lock CPU (Disable external debug access) */
-	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	sunxi_cpu_set_locking(cpu, true);
 
  	/* Power down CPU */
  	sunxi_cpu_set_power(cpuid, false);
 
-	/* Unlock CPU (Disable external debug access) */
-	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	/* Unlock CPU (Reenable external debug access) */
+	sunxi_cpu_set_locking(cpu, false);
  }
 

static u32 __secure cp15_read_scr(void)

arch/arm/cpu/armv7/sunxi/psci.c +6 -8
@@ -246,8 +320,6 @@ out:
  int __secure psci_cpu_on(u32 __always_unused unused, u32 mpidr, u32 pc,
  			 u32 context_id)
  {
-	struct sunxi_cpucfg_reg *cpucfg =
-		(struct sunxi_cpucfg_reg *)SUNXI_CPUCFG_BASE;
  	u32 cpu = (mpidr & 0x3);
 
  	/* store target PC and context id */
@@ -257,22 +329,22 @@ int __secure psci_cpu_on(u32 __always_unused 
 unused, u32 mpidr, u32 pc,
  	sunxi_set_entry_address(&psci_cpu_entry);
 
  	/* Assert reset on target CPU */
-	writel(0, &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, true);
 
  	/* Invalidate L1 cache */
-	clrbits_le32(&cpucfg->gen_ctrl, BIT(cpu));
+	sunxi_cpu_invalidate_cache(cpu);
 
  	/* Lock CPU (Disable external debug access) */
-	clrbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	sunxi_cpu_set_locking(cpu, true);
 
  	/* Power up target CPU */
  	sunxi_cpu_set_power(cpu, true);
 
  	/* De-assert reset on target CPU */
-	writel(BIT(1) | BIT(0), &cpucfg->cpu[cpu].rst);
+	sunxi_cpu_set_reset(cpu, false);
 
-	/* Unlock CPU (Disable external debug access) */
-	setbits_le32(&cpucfg->dbg_ctrl1, BIT(cpu));
+	/* Unlock CPU (Reenable external debug access) */
+	sunxi_cpu_set_locking(cpu, false);
 
  	return ARM_PSCI_RET_SUCCESS;
  }
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h +4 -2
index d01508517c..629d761aa6 100644
@@ -17,6 +17,8 @@
  #define SUNXI_SIDC_BASE			0x03006000
  #define SUNXI_SID_BASE			0x03006200
  #define SUNXI_TIMER_BASE		0x02050000
+#define SUNXI_GIC400_BASE		0x03020000
+#define SUNXI_CPUX_BASE			0x09010000
 
  #ifdef CONFIG_MACH_SUN50I_H6
  #define SUNXI_DRAM_COM_BASE		0x04002000
@@ -34,11 +36,11 @@
  #define SUNXI_SPI0_BASE			0x04025000
  #define SUNXI_SPI1_BASE			0x04026000
 
-#define SUNXI_RTC_BASE			0x07000000
  #define SUNXI_R_CPUCFG_BASE		0x07000400
  #define SUNXI_PRCM_BASE			0x07010000
  #define SUNXI_R_WDOG_BASE		0x07020400
-#define SUNXI_R_TWI_BASE		0x07081400
+#define SUNXI_R_TWI_BASE		0x07020800
+#define SUNXI_RTC_BASE			0x07090000
 
  #ifndef __ASSEMBLY__
  void sunxi_board_init(void);
arch/arm/mach-sunxi/Kconfig +2 -0
index bb9b863d2c..a5d312d377 100644
@@ -366,6 +366,8 @@ config MACH_SUN8I_R40
  config MACH_SUN8I_R528
  	bool "sun8i (Allwinner R528)"
  	select CPU_V7A
+	select CPU_V7_HAS_NONSEC
+	select ARCH_SUPPORT_PSCI
  	select SUNXI_GEN_NCAT2
  	select SUNXI_NEW_PINCTRL
  	select MMC_SUNXI_HAS_NEW_MODE
#34 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

Hey Andre,

Quoted 3 lines · Andre Przywara

So with "no success" you are referring to the patch below? Which is the Linux patch ported to U-Boot? And does that mean that the Linux patch works, but the U-Boot version doesn't?

Yes, the diff below is what I've been trying to use. It's not the Linux patch ported to U-Boot; I was trying to get it to work (wondering if there was something I was missing, like power control) when Maksim pointed out the Linux patch. I haven't tried the latter at all.

My "no success" is Linux stalling indefinitely at:

[    0.123090] smp: Bringing up secondary CPUs ...
Quoted 6 lines

The PRCM is routinely not documented in the user manuals, IIUC Allwinner provides separate documents for that (but not to us). So far this was all reverse engineered from either BSP code or some disassembly. Is there any indication in the BSP source code as to how this is supposed to work? And maybe there is no separate power control for the second core?

The user manual strongly suggests that power is enabled by default, so I may not need to touch PRCM after all. I also checked (and double-checked) the raw disassembly of my resulting psci_cpu_on and it does look like all of the correct registers are being hit.

I don't have any BSP source code suggesting anything otherwise. I do have an OP-TEE binary, which doesn't appear to try anything more than the kernel patch (and my current PSCI implementation) does.

Quoted 3 lines

And have you checked that the PSCI runtime code is correctly hooked up in U-Boot? I have to check what's really needed, but the whole code needs to be linked to secure SRAM, IIRC.

I'm about 80% sure the PSCI code is properly callable. I've toyed with the kernel a little bit to test this. I get a "bad mode" panic if U-Boot doesn't register the SMC vector, and PSCI_RET_NOT_SUPPORTED if I call unused function IDs, so I think U-Boot is able to get called and return just fine.

The OP-TEE binary also doesn't appear to try to relocate itself into any kind of particular RAM location. It just runs where it loads from DRAM. I take this to mean U-Boot's "in-situ" secure segment case is appropriate here, and no specific linking is needed.

The one thing I'm not very sure about at the moment is whether psci_cpu_entry is properly handling the newly-awakened second core. I'll keep debugging.

Quoted 1 line

We don't need #ifdef's, you can use normal C "if" statements:

I'll try to follow that approach then.

Quoted 1 line

This just requires to have all symbols defined all the time

Egh, gross, this means some code that shouldn't be used for a particular target can slip by the compiler's diagnostics unnoticed (such as when this happened with SUNXI_R_PIO_BASE). I wish there was a better way.

Quoted 3 lines

Sure. I actually removed most of the symbols there, as we don't need them, but can surely add the ones you found for PSCI. Do you need I2C in the SPL (looking at SUNXI_R_TWI_BASE)?

I'm not sure yet: my target does have an EEPROM on TWI2, which might eventually be used to store a board revision (and therefore which determines the FDT that the SPL should load), but I'm also considering overlays for other versions that are applied within main U-Boot.

But I can't fit much more in SPL anyway. The text section there is already up to 0x6ec0 (without SPI or NAND yet), and with third-party tooling assuming U-Boot at offset 0x8000, I can't very easily allocate more room to it. I might have to figure out what more to clear out here.

But anyway I only filled in that address because I came across the correct value in Allwinner's fork of U-Boot and noted it down before I forgot.

Cheers,
Sam

#35 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

Hey again Andre,

Quoted 2 lines · Sam Edwards

My "no success" is Linux stalling indefinitely at:
[    0.123090] smp: Bringing up secondary CPUs ...

OK, correction: my "no success" was Linux being unable to access the GIC, so boot was getting stuck. This was because it was running in nonsec mode and the GIC wasn't getting the interrupts moved over into group1.

The root cause of THAT was that the T113's CBAR's PERIPHBASE is still 0x01C80000, where the GIC used to be on the older ARM sunxis. Allwinner never updated their ARM cores when they moved the GIC to 0x03020000!

Guess we need a #define CFG_ARM_GIC_BASE_ADDRESS 0x03020000. Where do you recommend I put that? :)

I also think sunxi/psci.c:psci_arch_init needs some cleanup:
- It sets GICC_PMR to 0xFF, which should probably be removed because that was already done by _nonsec_init
- It tries to clear the NS bit of SCR to enter secure mode, but the NS bit is just enabled later in _secure_monitor. So that should also be removed because it has no effect.

So, I'll have a few PSCI patches for you soon -- once I rest up from all of that GIC debugging, that is!

Cheers,
Sam

#36 lore raw

Re: [RFC PATCH 10/17] clk: sunxi: Add support for the D1 CCU

On Mon, 29 May 2023 18:58:54 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 12 lines · Sam Edwards
Quoted 2 lines

My "no success" is Linux stalling indefinitely at:
[    0.123090] smp: Bringing up secondary CPUs ...

OK, correction: my "no success" was Linux being unable to access the GIC, so boot was getting stuck. This was because it was running in nonsec mode and the GIC wasn't getting the interrupts moved over into group1.

The root cause of THAT was that the T113's CBAR's PERIPHBASE is still 0x01C80000, where the GIC used to be on the older ARM sunxis. Allwinner never updated their ARM cores when they moved the GIC to 0x03020000!

Ah, good find! And yeah, I already noticed that on the H6 a few years back, but nobody really cares, and other SoCs get CBAR wrong as well (hence the existing workaround).

Quoted 2 lines

Guess we need a #define CFG_ARM_GIC_BASE_ADDRESS 0x03020000. Where do you recommend I put that? :)

Meh, the reflex would be to put it in include/configs/sunxi-common.h. Although I wonder if it really belongs into Kconfig, but that may be for another time.

Quoted 9 lines

I also think sunxi/psci.c:psci_arch_init needs some cleanup:
- It sets GICC_PMR to 0xFF, which should probably be removed because that was already done by _nonsec_init
- It tries to clear the NS bit of SCR to enter secure mode, but the NS bit is just enabled later in _secure_monitor. So that should also be removed because it has no effect.

So, I'll have a few PSCI patches for you soon -- once I rest up from all of that GIC debugging, that is!

Ah, sorry to hear that, the GIC can really be a beast ;-)

Cheers,
Andre

#37 lore raw

RFC PATCH 11/17 sunxi: clock: D1/R528: Enable PLL LDO during PLL1 setup

In reply to Andre Przywara

The D1/R528/T113s SoCs introduce a new "LDO enable" bit in the CPUX_PLL. Just enable that when we program that PLL.

---
 arch/arm/include/asm/arch-sunxi/clock_sun50i_h6.h |  1 +
 arch/arm/mach-sunxi/clock_sun50i_h6.c             | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
arch/arm/include/asm/arch-sunxi/clock_sun50i_h6.h +1 -0
index 37df4410eaa..9895c2c220e 100644
@@ -228,6 +228,7 @@ struct sunxi_ccm_reg {
 
 /* pll1 bit field */
 #define CCM_PLL1_CTRL_EN		BIT(31)
+#define CCM_PLL1_LDO_EN			BIT(30)
 #define CCM_PLL1_LOCK_EN		BIT(29)
 #define CCM_PLL1_LOCK			BIT(28)
 #define CCM_PLL1_OUT_EN			BIT(27)
arch/arm/mach-sunxi/clock_sun50i_h6.c +7 -5
index 7926394cf76..90110eab101 100644
@@ -86,11 +86,13 @@ void clock_set_pll1(unsigned int clk)
 	writel(val, &ccm->cpu_axi_cfg);
 
 	/* clk = 24*n/p, p is ignored if clock is >288MHz */
-	writel(CCM_PLL1_CTRL_EN | CCM_PLL1_LOCK_EN | CCM_PLL1_CLOCK_TIME_2 |
-#ifdef CONFIG_MACH_SUN50I_H616
-	       CCM_PLL1_OUT_EN |
-#endif
-	       CCM_PLL1_CTRL_N(clk / 24000000), &ccm->pll1_cfg);
+	val = CCM_PLL1_CTRL_EN | CCM_PLL1_LOCK_EN | CCM_PLL1_CLOCK_TIME_2;
+	val |= CCM_PLL1_CTRL_N(clk / 24000000);
+	if (IS_ENABLED(CONFIG_MACH_SUN50I_H616))
+	       val |= CCM_PLL1_OUT_EN;
+	if (IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2))
+	       val |= CCM_PLL1_OUT_EN | CCM_PLL1_LDO_EN;
+	writel(val, &ccm->pll1_cfg);
 	while (!(readl(&ccm->pll1_cfg) & CCM_PLL1_LOCK)) {}
 
 	/* Switch CPU to PLL1 */
Signature · 1 line
2.35.5
#38 lore raw

RFC PATCH 12/17 sunxi: clock: support D1/R528 PLL6 clock

In reply to Andre Przywara

The PLL_PERIPH0 clock changed a bit in the D1/R528/T113s SoCs: there is new P0 divider at bits [18:16], and the M divider is 1.

Add code to support this version of "PLL6".

---
 .../include/asm/arch-sunxi/clock_sun50i_h6.h  |  2 ++
 arch/arm/mach-sunxi/clock_sun50i_h6.c         | 24 +++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)
arch/arm/include/asm/arch-sunxi/clock_sun50i_h6.h +2 -0
index 9895c2c220e..8471e11aa02 100644
@@ -249,6 +249,8 @@ struct sunxi_ccm_reg {
 #define CCM_PLL6_CTRL_EN		BIT(31)
 #define CCM_PLL6_LOCK_EN		BIT(29)
 #define CCM_PLL6_LOCK			BIT(28)
+#define CCM_PLL6_CTRL_P0_SHIFT		16
+#define CCM_PLL6_CTRL_P0_MASK		(0x7 << CCM_PLL6_CTRL_P0_SHIFT)
 #define CCM_PLL6_CTRL_N_SHIFT		8
 #define CCM_PLL6_CTRL_N_MASK		(0xff << CCM_PLL6_CTRL_N_SHIFT)
 #define CCM_PLL6_CTRL_DIV1_SHIFT	0
arch/arm/mach-sunxi/clock_sun50i_h6.c +17 -7
index 90110eab101..607efe6a9c1 100644
@@ -107,16 +107,26 @@ unsigned int clock_get_pll6(void)
 {
 	struct sunxi_ccm_reg *const ccm =
 		(struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
-	int m = IS_ENABLED(CONFIG_MACH_SUN50I_H6) ? 4 : 2;
-
 	uint32_t rval = readl(&ccm->pll6_cfg);
 	int n = ((rval & CCM_PLL6_CTRL_N_MASK) >> CCM_PLL6_CTRL_N_SHIFT) + 1;
-	int div1 = ((rval & CCM_PLL6_CTRL_DIV1_MASK) >>
-			CCM_PLL6_CTRL_DIV1_SHIFT) + 1;
 	int div2 = ((rval & CCM_PLL6_CTRL_DIV2_MASK) >>
-			CCM_PLL6_CTRL_DIV2_SHIFT) + 1;
-	/* The register defines PLL6-2X or PLL6-4X, not plain PLL6 */
-	return 24000000 / m * n / div1 / div2;
+		    CCM_PLL6_CTRL_DIV2_SHIFT) + 1;
+	int div1, m;
+
+	if (IS_ENABLED(CONFIG_SUNXI_GEN_NCAT2)) {
+		div1 = ((rval & CCM_PLL6_CTRL_P0_MASK) >>
+			CCM_PLL6_CTRL_P0_SHIFT) + 1;
+		m = 1;
+	} else {
+		div1 = ((rval & CCM_PLL6_CTRL_DIV1_MASK) >>
+			CCM_PLL6_CTRL_DIV1_SHIFT) + 1;
+		if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
+			m = 4;
+		else
+			m = 2;
+	}
+
+	return 24000000U * n / m / div1 / div2;
 }
 
 int clock_twi_onoff(int port, int state)
Signature · 1 line
2.35.5
#39 lore raw

RFC PATCH 13/17 sunxi: add early Allwinner R528/T113 SoC support

In reply to Andre Przywara

This adds the remaining code bits to teach U-Boot about Allwinner's newest SoC generation. This was introduced with the RISC-V based Allwinner D1 SoC, which actually shares a die with the ARM cores versions called R528 (BGA, without DRAM) and T113s (QFP, with embedded DRAM).

This adds the new Kconfig stanza, using the two newly introduced symbols for the new SoC generation and pincontroller. It also adds the new symbols to the relavent code places, to set all the hardcoded bits directly.

We just chicken out the DRAM controller code for now with a stub to make it compile. There is GPLed code out there that can be used, although that still looks very much like the disassembly/decompile it came from.

---
 .../arm/include/asm/arch-sunxi/clock_sun50i_h6.h |  5 +++++
 arch/arm/mach-sunxi/Kconfig                      | 16 ++++++++++++++++
 arch/arm/mach-sunxi/board.c                      |  4 ++++
 arch/arm/mach-sunxi/clock_sun50i_h6.c            |  2 ++
 arch/arm/mach-sunxi/cpu_info.c                   |  2 ++
 board/sunxi/Makefile                             |  1 +
 board/sunxi/dram_sun8i_r528.c                    |  9 +++++++++
 drivers/mmc/sunxi_mmc.c                          |  1 +
 drivers/pinctrl/sunxi/Kconfig                    |  1 +
 9 files changed, 41 insertions(+)
 create mode 100644 board/sunxi/dram_sun8i_r528.c
arch/arm/include/asm/arch-sunxi/clock_sun50i_h6.h +5 -0
index 8471e11aa02..d34a9baf5e1 100644
@@ -288,6 +288,11 @@ struct sunxi_ccm_reg {
 
 /* apb1 bit field */
 #define CCM_APB1_DEFAULT		0x03000102
+#elif CONFIG_MACH_SUN8I_R528
+#define CCM_PLL6_DEFAULT		0xe8216300
+#define CCM_PSI_AHB1_AHB2_DEFAULT	0x03000002
+//#define CCM_AHB3_DEFAULT		0x03000002
+#define CCM_APB1_DEFAULT		0x03000102
 #endif
 
 /* apb2 bit field */
arch/arm/mach-sunxi/Kconfig +16 -0
index b59db212fa8..71799686a05 100644
@@ -51,6 +51,12 @@ config DRAM_SUN50I_H616
 	  Select this dram controller driver for some sun50i platforms,
 	  like H616.
 
+config DRAM_SUN8I_R528
+	bool
+	help
+	  Select this DRAM controller driver for the R528, T113, D1
+	  and D1s/F133 SoC.
+
 if DRAM_SUN50I_H616
 config DRAM_SUN50I_H616_WRITE_LEVELING
 	bool "H616 DRAM write leveling"
@@ -318,6 +324,15 @@ config MACH_SUN8I_R40
 	select PHY_SUN4I_USB
 	imply SPL_SYS_I2C_LEGACY
 
+config MACH_SUN8I_R528
+	bool "sun8i (Allwinner R528)"
+	select CPU_V7A
+	select SUNXI_GEN_NCAT2
+	select SUNXI_NEW_PINCTRL
+	select MMC_SUNXI_HAS_NEW_MODE
+	select SUPPORT_SPL
+	select DRAM_SUN8I_R528
+
 config MACH_SUN8I_V3S
 	bool "sun8i (Allwinner V3/V3s/S3/S3L)"
 	select CPU_V7A
@@ -622,6 +637,7 @@ config SYS_CONFIG_NAME
 	default "sun6i" if MACH_SUN6I
 	default "sun7i" if MACH_SUN7I
 	default "sun8i" if MACH_SUN8I
+	default "sun8i" if MACH_SUN8I_R528
 	default "sun9i" if MACH_SUN9I
 	default "sun50i" if MACH_SUN50I
 	default "sun50i" if MACH_SUN50I_H6
arch/arm/mach-sunxi/board.c +4 -0
index 3763ec3d2e4..33331cda5e2 100644
@@ -148,6 +148,10 @@ static int gpio_init(void)
 	sunxi_gpio_set_cfgpin(SUNXI_GPH(12), SUN9I_GPH_UART0);
 	sunxi_gpio_set_cfgpin(SUNXI_GPH(13), SUN9I_GPH_UART0);
 	sunxi_gpio_set_pull(SUNXI_GPH(13), SUNXI_GPIO_PULL_UP);
+#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_MACH_SUN8I_R528)
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(2), 6);
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(3), 6);
+	sunxi_gpio_set_pull(SUNXI_GPE(3), SUNXI_GPIO_PULL_UP);
 #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_MACH_SUNIV)
 	sunxi_gpio_set_cfgpin(SUNXI_GPA(2), SUNIV_GPE_UART0);
 	sunxi_gpio_set_cfgpin(SUNXI_GPA(3), SUNIV_GPE_UART0);
arch/arm/mach-sunxi/clock_sun50i_h6.c +2 -0
index 607efe6a9c1..4d5e23a9af4 100644
@@ -38,7 +38,9 @@ void clock_init_safe(void)
 			CCM_CPU_AXI_DEFAULT_FACTORS);
 
 	writel(CCM_PSI_AHB1_AHB2_DEFAULT, &ccm->psi_ahb1_ahb2_cfg);
+#ifdef CCM_AHB3_DEFAULT
 	writel(CCM_AHB3_DEFAULT, &ccm->ahb3_cfg);
+#endif
 	writel(CCM_APB1_DEFAULT, &ccm->apb1_cfg);
 
 	/*
arch/arm/mach-sunxi/cpu_info.c +2 -0
index 7eef178859b..7fecc3b88dd 100644
@@ -93,6 +93,8 @@ int print_cpuinfo(void)
 	printf("CPU:   Allwinner R40 (SUN8I %04x)\n", sunxi_get_sram_id());
 #elif defined CONFIG_MACH_SUN8I_V3S
 	printf("CPU:   Allwinner V3s (SUN8I %04x)\n", sunxi_get_sram_id());
+#elif defined CONFIG_MACH_SUN8I_R528
+	puts("CPU:   Allwinner R528 (SUN8I)\n");
 #elif defined CONFIG_MACH_SUN9I
 	puts("CPU:   Allwinner A80 (SUN9I)\n");
 #elif defined CONFIG_MACH_SUN50I
board/sunxi/Makefile +1 -0
index 7763b032c80..db16cf247c6 100644
@@ -12,4 +12,5 @@ obj-$(CONFIG_SUN7I_GMAC)	+= gmac.o
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
 obj-$(CONFIG_MACH_SUN7I)	+= dram_sun5i_auto.o
+obj-$(CONFIG_DRAM_SUN8I_R528)	+= dram_sun8i_r528.o
 obj-$(CONFIG_CHIP_DIP_SCAN)	+= chip.o
board/sunxi/dram_sun8i_r528.c new file +9 -0
new file mode 100644
index 00000000000..84261df1cd8
@@ -0,0 +1,9 @@
+/*
+ * Quick hack to make it compile, we cannot use the SPL just yet.
+ * There is GPLed DRAM code in awboot, to be lifted here, after some
+ * massaging.
+ */
+unsigned long sunxi_dram_init(void)
+{
+	return 128 * 1024 * 1024;
+}
drivers/mmc/sunxi_mmc.c +1 -0
index 6ce2729473c..59b1bbd4a9c 100644
@@ -736,6 +736,7 @@ static const struct udevice_id sunxi_mmc_ids[] = {
 	{ .compatible = "allwinner,sun50i-h6-emmc" },
 	{ .compatible = "allwinner,sun50i-a100-mmc" },
 	{ .compatible = "allwinner,sun50i-a100-emmc" },
+	{ .compatible = "allwinner,sun20i-d1-mmc" },
 	{ /* sentinel */ }
 };
 
drivers/pinctrl/sunxi/Kconfig +1 -0
index c8f937d91e9..cbd61795986 100644
@@ -126,6 +126,7 @@ config PINCTRL_SUN50I_H616_R
 
 config PINCTRL_SUN20I_D1
 	bool "Support for the Allwinner D1/R528 PIO"
+	default MACH_SUN8I_R528
 	select PINCTRL_SUNXI
 
 endif
Signature · 1 line
2.35.5
#40 lore raw

Re: [RFC PATCH 13/17] sunxi: add early Allwinner R528/T113 SoC support

Quoted 5 lines · Andre Przywara
arch/arm/mach-sunxi/board.c +0 -0
index 3763ec3d2e4..33331cda5e2 100644

arch/arm/mach-sunxi/board.c static int gpio_init(void) · line 157

Quoted 10 lines
arch/arm/mach-sunxi/board.c +4 -0
@@ -148,6 +148,10 @@ static int gpio_init(void)
  	sunxi_gpio_set_cfgpin(SUNXI_GPH(12), SUN9I_GPH_UART0);
  	sunxi_gpio_set_cfgpin(SUNXI_GPH(13), SUN9I_GPH_UART0);
  	sunxi_gpio_set_pull(SUNXI_GPH(13), SUNXI_GPIO_PULL_UP);
+#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_MACH_SUN8I_R528)
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(2), 6);
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(3), 6);
+	sunxi_gpio_set_pull(SUNXI_GPE(3), SUNXI_GPIO_PULL_UP);
  #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_MACH_SUNIV)
  	sunxi_gpio_set_cfgpin(SUNXI_GPA(2), SUNIV_GPE_UART0);
  	sunxi_gpio_set_cfgpin(SUNXI_GPA(3), SUNIV_GPE_UART0);

I'm a relative outsider to sunxi, but it does look like the NCAT2 generation's MUX is a lot more flexible in its UART assignments: e.g. while H3's UART1-3 only had one set of pins each UART could use, the T113 (my target) supports anywhere from 2-6 (typically 4) different options for each of its UARTs. It is not as simple as configuring which UART is the serial console anymore, because different boards might wire the console header to different pins. My particular target uses UART3 on pins PB6/PB7, for example.

Since this patchset is updating the PIO driver anyway, maybe it's worth updating the (preprocessor, not runtime) logic in gpio_init to support getting the UART TX/RX pins from Kconfig, validating that the CONFIG_CONS_INDEX and pin selection are compatible, and setting the correct MUX function for those pins with a value pulled from a table?

#41 lore raw

Re: [RFC PATCH 13/17] sunxi: add early Allwinner R528/T113 SoC support

On Mon, 15 May 2023 20:52:23 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 17 lines · Andre Przywara
Quoted 5 lines
arch/arm/mach-sunxi/board.c +0 -0
index 3763ec3d2e4..33331cda5e2 100644

arch/arm/mach-sunxi/board.c static int gpio_init(void) · line 157

Quoted 10 lines
arch/arm/mach-sunxi/board.c +4 -0
@@ -148,6 +148,10 @@ static int gpio_init(void)
  	sunxi_gpio_set_cfgpin(SUNXI_GPH(12), SUN9I_GPH_UART0);
  	sunxi_gpio_set_cfgpin(SUNXI_GPH(13), SUN9I_GPH_UART0);
  	sunxi_gpio_set_pull(SUNXI_GPH(13), SUNXI_GPIO_PULL_UP);
+#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_MACH_SUN8I_R528)
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(2), 6);
+	sunxi_gpio_set_cfgpin(SUNXI_GPE(3), 6);
+	sunxi_gpio_set_pull(SUNXI_GPE(3), SUNXI_GPIO_PULL_UP);
  #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_MACH_SUNIV)
  	sunxi_gpio_set_cfgpin(SUNXI_GPA(2), SUNIV_GPE_UART0);
  	sunxi_gpio_set_cfgpin(SUNXI_GPA(3), SUNIV_GPE_UART0);  
Quoted 8 lines

I'm a relative outsider to sunxi, but it does look like the NCAT2 generation's MUX is a lot more flexible in its UART assignments: e.g. while H3's UART1-3 only had one set of pins each UART could use, the T113 (my target) supports anywhere from 2-6 (typically 4) different options for each of its UARTs. It is not as simple as configuring which UART is the serial console anymore, because different boards might wire the console header to different pins. My particular target uses UART3 on pins PB6/PB7, for example.

Well, theoretically there are indeed quite some options, but in reality we find that most boards follow some reference design, and the *debug* UART is only ever using a very few of the possible settings. For the later (ARMv8) SoCs this is mostly UART0, but for the T113 it's apparently indeed UART3. I also changed that in the Github version, to use the very same PB6/7 UART3 mux as you.

Quoted 5 lines

Since this patchset is updating the PIO driver anyway, maybe it's worth updating the (preprocessor, not runtime) logic in gpio_init to support getting the UART TX/RX pins from Kconfig, validating that the CONFIG_CONS_INDEX and pin selection are compatible, and setting the correct MUX function for those pins with a value pulled from a table?

Mmmh, that's an idea one could follow, as this function is indeed insane. I actually rewrote gpio_init() already, to replace the hard to read #ifdef's with actual C if statements, though that's still following the same idea as the current code.
Let me have a look how this would look like.

Cheers,
Andre

#42 lore raw

RFC PATCH 14/17 sunxi: refactor serial base addresses to avoid asm/arch/cpu.h

In reply to Andre Przywara

At the moment we have each SoC's memory map defined in its own cpu.h, which is included in include/configs/sunxi_common.h. This will be a problem with the introduction of Allwinner RISC-V support.

Remove the inclusion of that header file from the common config header, instead move the required serial base addresses (for the SPL) into a separate header file. Then include the original cpu.h file only where we really need it, which is only under arch/arm now.

This disentangles the architecture specific header files from the generic code.

---
 arch/arm/cpu/armv7/sunxi/sram.c               |  1 +
 arch/arm/cpu/armv8/fel_utils.S                |  1 +
 arch/arm/include/asm/arch-sunxi/clock.h       |  1 +
 arch/arm/include/asm/arch-sunxi/cpu_sun4i.h   | 15 ---------
 .../include/asm/arch-sunxi/cpu_sun50i_h6.h    |  5 ---
 arch/arm/include/asm/arch-sunxi/cpu_sun9i.h   |  7 ----
 .../include/asm/arch-sunxi/cpu_sunxi_ncat2.h  |  5 ---
 arch/arm/include/asm/arch-sunxi/serial.h      | 32 +++++++++++++++++++
 arch/arm/mach-sunxi/gtbus_sun9i.c             |  1 +
 arch/arm/mach-sunxi/timer.c                   |  1 +
 include/configs/sunxi-common.h                |  2 +-
 11 files changed, 38 insertions(+), 33 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-sunxi/serial.h
arch/arm/cpu/armv7/sunxi/sram.c +1 -0
index 28564c2846a..28ff6a1b7c2 100644
@@ -12,6 +12,7 @@
 #include <common.h>
 #include <init.h>
 #include <asm/io.h>
+#include <asm/arch/cpu.h>
 
 void sunxi_sram_init(void)
 {
arch/arm/cpu/armv8/fel_utils.S +1 -0
index 5266515f145..9b1d55bb31a 100644
@@ -10,6 +10,7 @@
 #include <config.h>
 #include <asm/system.h>
 #include <linux/linkage.h>
+#include <asm/arch/cpu.h>
 
 /*
  * We don't overwrite save_boot_params() here, to save the FEL state upon
arch/arm/include/asm/arch-sunxi/clock.h +1 -0
index 3d34261b0e5..fcc8966cb0b 100644
@@ -9,6 +9,7 @@
 #define _SUNXI_CLOCK_H
 
 #include <linux/types.h>
+#include <asm/arch/cpu.h>
 
 #define CLK_GATE_OPEN			0x1
 #define CLK_GATE_CLOSE			0x0
arch/arm/include/asm/arch-sunxi/cpu_sun4i.h +0 -15
index d6fe51f24bc..3daee2f574a 100644
@@ -128,20 +128,6 @@ defined(CONFIG_MACH_SUN50I)
 #define SUNXI_CPUCFG_BASE		0x01c25c00
 #endif
 
-#ifdef CONFIG_MACH_SUNIV
-#define SUNXI_UART0_BASE		0x01c25000
-#define SUNXI_UART1_BASE		0x01c25400
-#define SUNXI_UART2_BASE		0x01c25800
-#else
-#define SUNXI_UART0_BASE		0x01c28000
-#define SUNXI_UART1_BASE		0x01c28400
-#define SUNXI_UART2_BASE		0x01c28800
-#endif
-#define SUNXI_UART3_BASE		0x01c28c00
-#define SUNXI_UART4_BASE		0x01c29000
-#define SUNXI_UART5_BASE		0x01c29400
-#define SUNXI_UART6_BASE		0x01c29800
-#define SUNXI_UART7_BASE		0x01c29c00
 #define SUNXI_PS2_0_BASE		0x01c2a000
 #define SUNXI_PS2_1_BASE		0x01c2a400
 
@@ -208,7 +194,6 @@ defined(CONFIG_MACH_SUN50I)
 #endif
 
 #define SUNXI_R_TWI_BASE		0x01f02400
-#define SUNXI_R_UART_BASE		0x01f02800
 #define SUN6I_P2WI_BASE			0x01f03400
 #define SUNXI_RSB_BASE			0x01f03400
 
arch/arm/include/asm/arch-sunxi/cpu_sun50i_h6.h +0 -5
index 9b6bf843601..15ee092d358 100644
@@ -42,10 +42,6 @@
 #define SUNXI_DRAM_PHY0_BASE		0x04800000
 #endif
 
-#define SUNXI_UART0_BASE		0x05000000
-#define SUNXI_UART1_BASE		0x05000400
-#define SUNXI_UART2_BASE		0x05000800
-#define SUNXI_UART3_BASE		0x05000C00
 #define SUNXI_TWI0_BASE			0x05002000
 #define SUNXI_TWI1_BASE			0x05002400
 #define SUNXI_TWI2_BASE			0x05002800
@@ -67,7 +63,6 @@
 #define SUNXI_R_CPUCFG_BASE		0x07000400
 #define SUNXI_PRCM_BASE			0x07010000
 #define SUNXI_R_WDOG_BASE		0x07020400
-#define SUNXI_R_UART_BASE		0x07080000
 #define SUNXI_R_TWI_BASE		0x07081400
 
 #ifndef __ASSEMBLY__
arch/arm/include/asm/arch-sunxi/cpu_sun9i.h +0 -7
index 20025be2319..2bf2675d5c1 100644
@@ -86,12 +86,6 @@
 #define SUNXI_LRADC_BASE		(REGS_APB0_BASE + 0x1800)
 
 /* APB1 Module */
-#define SUNXI_UART0_BASE		(REGS_APB1_BASE + 0x0000)
-#define SUNXI_UART1_BASE		(REGS_APB1_BASE + 0x0400)
-#define SUNXI_UART2_BASE		(REGS_APB1_BASE + 0x0800)
-#define SUNXI_UART3_BASE		(REGS_APB1_BASE + 0x0C00)
-#define SUNXI_UART4_BASE		(REGS_APB1_BASE + 0x1000)
-#define SUNXI_UART5_BASE		(REGS_APB1_BASE + 0x1400)
 #define SUNXI_TWI0_BASE			(REGS_APB1_BASE + 0x2800)
 #define SUNXI_TWI1_BASE			(REGS_APB1_BASE + 0x2C00)
 #define SUNXI_TWI2_BASE			(REGS_APB1_BASE + 0x3000)
@@ -100,7 +94,6 @@
 
 /* RCPUS Module */
 #define SUNXI_PRCM_BASE			(REGS_RCPUS_BASE + 0x1400)
-#define SUNXI_R_UART_BASE		(REGS_RCPUS_BASE + 0x2800)
 #define SUNXI_RSB_BASE			(REGS_RCPUS_BASE + 0x3400)
 
 /* Misc. */
arch/arm/include/asm/arch-sunxi/cpu_sunxi_ncat2.h +0 -5
index 13093085a5e..d01508517c3 100644
@@ -27,10 +27,6 @@
 #define SUNXI_MMC1_BASE			0x04021000
 #define SUNXI_MMC2_BASE			0x04022000
 
-#define SUNXI_UART0_BASE		0x02500000
-#define SUNXI_UART1_BASE		0x02500400
-#define SUNXI_UART2_BASE		0x02500800
-#define SUNXI_UART3_BASE		0x02500C00
 #define SUNXI_TWI0_BASE			0x02502000
 #define SUNXI_TWI1_BASE			0x02502400
 #define SUNXI_TWI2_BASE			0x02502800
@@ -42,7 +38,6 @@
 #define SUNXI_R_CPUCFG_BASE		0x07000400
 #define SUNXI_PRCM_BASE			0x07010000
 #define SUNXI_R_WDOG_BASE		0x07020400
-#define SUNXI_R_UART_BASE		0x07080000
 #define SUNXI_R_TWI_BASE		0x07081400
 
 #ifndef __ASSEMBLY__
arch/arm/include/asm/arch-sunxi/serial.h new file +32 -0
new file mode 100644
index 00000000000..9386287b65e
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ *  hardcoded UART base addresses for early SPL use
+ *
+ *  Copyright (c) 2022  Arm Ltd.
+ */
+
+#ifndef SUNXI_SERIAL_MEMMAP_H
+#define SUNXI_SERIAL_MEMMAP_H
+
+#if defined(CONFIG_MACH_SUN9I)
+#define SUNXI_UART0_BASE		0x07000000
+#define SUNXI_R_UART_BASE		0x08002800
+#elif defined(CONFIG_SUN50I_GEN_H6)
+#define SUNXI_UART0_BASE		0x05000000
+#define SUNXI_R_UART_BASE		0x07080000
+#elif defined(CONFIG_MACH_SUNIV)
+#define SUNXI_UART0_BASE		0x01c25000
+#define SUNXI_R_UART_BASE		0
+#elif defined(CONFIG_SUNXI_GEN_NCAT2)
+#define SUNXI_UART0_BASE		0x02500000
+#define SUNXI_R_UART_BASE		0		// 0x07080000 (?>
+#else
+#define SUNXI_UART0_BASE		0x01c28000
+#define SUNXI_R_UART_BASE		0x01f02800
+#endif
+
+#define SUNXI_UART1_BASE		(SUNXI_UART0_BASE + 0x400)
+#define SUNXI_UART2_BASE		(SUNXI_UART0_BASE + 0x800)
+#define SUNXI_UART3_BASE		(SUNXI_UART0_BASE + 0xc00)
+
+#endif /* SUNXI_SERIAL_MEMMAP_H */
arch/arm/mach-sunxi/gtbus_sun9i.c +1 -0
index cf011c4cfa7..5624621b500 100644
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <asm/io.h>
+#include <asm/arch/cpu.h>
 #include <asm/arch/gtbus_sun9i.h>
 #include <asm/arch/sys_proto.h>
 
arch/arm/mach-sunxi/timer.c +1 -0
index fc9d419a25e..9a6f6c06d8c 100644
@@ -10,6 +10,7 @@
 #include <time.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <asm/arch/cpu.h>
 #include <asm/arch/timer.h>
 #include <linux/delay.h>
 
include/configs/sunxi-common.h +1 -1
index 720768629d6..d594e9aaf88 100644
@@ -12,7 +12,6 @@
 #ifndef _SUNXI_COMMON_CONFIG_H
 #define _SUNXI_COMMON_CONFIG_H
 
-#include <asm/arch/cpu.h>
 #include <linux/stringify.h>
 
 /* Serial & console */
@@ -25,6 +24,7 @@
 #define CONFIG_SYS_NS16550_CLK		24000000
 #endif
 #ifndef CONFIG_DM_SERIAL
+#include <asm/arch/serial.h>
 # define CONFIG_SYS_NS16550_REG_SIZE	-4
 # define CONFIG_SYS_NS16550_COM1		SUNXI_UART0_BASE
 # define CONFIG_SYS_NS16550_COM2		SUNXI_UART1_BASE
Signature · 1 line
2.35.5
#43 lore raw

RFC PATCH 15/17 riscv: dts: allwinner: Add the D1/D1s SoC devicetree

In reply to Andre Przywara

From: Samuel Holland <[email protected]>

D1 (aka D1-H), D1s (aka F133), R528, and T113 are a family of SoCs based on a single die, or at a pair of dies derived from the same design.

D1 and D1s contain a single T-HEAD Xuantie C906 CPU, whereas R528 and T113 contain a pair of Cortex-A7's. D1 and R528 are the full version of the chip with a BGA package, whereas D1s and T113 are low-pin-count QFP variants.

Because the original design supported both ARM and RISC-V CPUs, some peripherals are duplicated. In addition, all variants except D1s contain a HiFi 4 DSP with its own set of peripherals.

The devicetrees are organized to minimize duplication:
- Common perhiperals are described in sunxi-d1s-t113.dtsi
- DSP-related peripherals are described in sunxi-d1-t113.dtsi
- RISC-V specific hardware is described in sun20i-d1s.dtsi
- Functionality unique to the D1 variant is described in sun20i-d1.dtsi

The SOC_PERIPHERAL_IRQ macro handles the different #interrupt-cells values between the ARM (GIC) and RISC-V (PLIC) versions of the SoC.

---
 arch/riscv/dts/sun20i-d1.dtsi               |  66 ++
 arch/riscv/dts/sun20i-d1s.dtsi              |  76 ++
 arch/riscv/dts/sunxi-d1-t113.dtsi           |  15 +
 arch/riscv/dts/sunxi-d1s-t113.dtsi          | 844 ++++++++++++++++++++
 include/dt-bindings/clock/sun20i-d1-r-ccu.h |  19 +
 include/dt-bindings/reset/sun20i-d1-r-ccu.h |  16 +
 6 files changed, 1036 insertions(+)
 create mode 100644 arch/riscv/dts/sun20i-d1.dtsi
 create mode 100644 arch/riscv/dts/sun20i-d1s.dtsi
 create mode 100644 arch/riscv/dts/sunxi-d1-t113.dtsi
 create mode 100644 arch/riscv/dts/sunxi-d1s-t113.dtsi
 create mode 100644 include/dt-bindings/clock/sun20i-d1-r-ccu.h
 create mode 100644 include/dt-bindings/reset/sun20i-d1-r-ccu.h
arch/riscv/dts/sun20i-d1.dtsi new file +66 -0
new file mode 100644
index 00000000000..97e7cbb3259
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2021-2022 Samuel Holland <[email protected]>
+
+#include "sun20i-d1s.dtsi"
+#include "sunxi-d1-t113.dtsi"
+
+/ {
+	soc {
+		lradc: keys@2009800 {
+			compatible = "allwinner,sun20i-d1-lradc",
+				     "allwinner,sun50i-r329-lradc";
+			reg = <0x2009800 0x400>;
+			interrupts = <SOC_PERIPHERAL_IRQ(61) IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_LRADC>;
+			resets = <&ccu RST_BUS_LRADC>;
+			status = "disabled";
+		};
+
+		i2s0: i2s@2032000 {
+			compatible = "allwinner,sun20i-d1-i2s",
+				     "allwinner,sun50i-r329-i2s";
+			reg = <0x2032000 0x1000>;
+			interrupts = <SOC_PERIPHERAL_IRQ(26) IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&ccu CLK_BUS_I2S0>,
+				 <&ccu CLK_I2S0>;
+			clock-names = "apb", "mod";
+			resets = <&ccu RST_BUS_I2S0>;
+			dmas = <&dma 3>, <&dma 3>;
+			dma-names = "rx", "tx";
+			status = "disabled";
+			#sound-dai-cells = <0>;
+		};
+	};
+};
+
+&pio {
+	/omit-if-no-ref/
+	dmic_pb11_d0_pin: dmic-pb11-d0-pin {
+		pins = "PB11";
+		function = "dmic";
+	};
+
+	/omit-if-no-ref/
+	dmic_pe17_clk_pin: dmic-pe17-clk-pin {
+		pins = "PE17";
+		function = "dmic";
+	};
+
+	/omit-if-no-ref/
+	i2c0_pb10_pins: i2c0-pb10-pins {
+		pins = "PB10", "PB11";
+		function = "i2c0";
+	};
+
+	/omit-if-no-ref/
+	i2c2_pb0_pins: i2c2-pb0-pins {
+		pins = "PB0", "PB1";
+		function = "i2c2";
+	};
+
+	/omit-if-no-ref/
+	uart0_pb8_pins: uart0-pb8-pins {
+		pins = "PB8", "PB9";
+		function = "uart0";
+	};
+};
arch/riscv/dts/sun20i-d1s.dtsi new file +76 -0

76 lines not on this page · raw message

arch/riscv/dts/sunxi-d1-t113.dtsi new file +15 -0
new file mode 100644
index 00000000000..b7156123df5
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2021-2022 Samuel Holland <[email protected]>
+
+/ {
+	soc {
+		dsp_wdt: watchdog@1700400 {
+			compatible = "allwinner,sun20i-d1-wdt";
+			reg = <0x1700400 0x20>;
+			interrupts = <SOC_PERIPHERAL_IRQ(122) IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&dcxo>, <&rtc CLK_OSC32K>;
+			clock-names = "hosc", "losc";
+			status = "reserved";
+		};
+	};
+};
arch/riscv/dts/sunxi-d1s-t113.dtsi new file +844 -0

844 lines not on this page · raw message

include/dt-bindings/clock/sun20i-d1-r-ccu.h new file +19 -0
new file mode 100644
index 00000000000..4c2697fd32b
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: (GPL-2.0+ or MIT) */
+/*
+ * Copyright (C) 2021 Samuel Holland <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_
+#define _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_
+
+#define CLK_R_AHB		0
+
+#define CLK_BUS_R_TIMER		2
+#define CLK_BUS_R_TWD		3
+#define CLK_BUS_R_PPU		4
+#define CLK_R_IR_RX		5
+#define CLK_BUS_R_IR_RX		6
+#define CLK_BUS_R_RTC		7
+#define CLK_BUS_R_CPUCFG	8
+
+#endif /* _DT_BINDINGS_CLK_SUN20I_D1_R_CCU_H_ */
include/dt-bindings/reset/sun20i-d1-r-ccu.h new file +16 -0
new file mode 100644
index 00000000000..d93d6423d28
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: (GPL-2.0+ or MIT) */
+/*
+ * Copyright (C) 2021 Samuel Holland <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_
+#define _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_
+
+#define RST_BUS_R_TIMER		0
+#define RST_BUS_R_TWD		1
+#define RST_BUS_R_PPU		2
+#define RST_BUS_R_IR_RX		3
+#define RST_BUS_R_RTC		4
+#define RST_BUS_R_CPUCFG	5
+
+#endif /* _DT_BINDINGS_RST_SUN20I_D1_R_CCU_H_ */
Signature · 1 line
2.35.5
#44 lore raw

RFC PATCH 16/17 arm: sunxi: add Allwinner T113s devicetree stub

In reply to Andre Przywara

This adds the basic SoC .dtsi devicetree stub for the Allwinner T113s SoC. This shares a die with the Allwinner D1 SoC (with RISC-V cores), but uses two Cortex-A7 cores instead of the T-HEAD C906 RISC-V core.

Include the existing D1 devicetree stub, but add the ARM specific nodes, like for the CPU, the arch timer and the GIC.

---
 arch/arm/dts/sun8i-t113s.dtsi | 59 +++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 arch/arm/dts/sun8i-t113s.dtsi
arch/arm/dts/sun8i-t113s.dtsi new file +59 -0
new file mode 100644
index 00000000000..0919ce559f6
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2022 Arm Ltd.
+
+#define SOC_PERIPHERAL_IRQ(nr)	GIC_SPI nr
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <../../riscv/dts/sunxi-d1s-t113.dtsi>
+#include <../../riscv/dts/sunxi-d1-t113.dtsi>
+
+/ {
+	interrupt-parent = <&gic>;
+
+	cpus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		cpu0: cpu@0 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <0>;
+			clocks = <&ccu CLK_CPUX>;
+			clock-names = "cpu";
+		};
+
+		cpu1: cpu@1 {
+			compatible = "arm,cortex-a7";
+			device_type = "cpu";
+			reg = <1>;
+			clocks = <&ccu CLK_CPUX>;
+			clock-names = "cpu";
+		};
+	};
+
+	gic: interrupt-controller@1c81000 {
+		compatible = "arm,gic-400";
+		reg = <0x03021000 0x1000>,
+		      <0x03022000 0x2000>,
+		      <0x03024000 0x2000>,
+		      <0x03026000 0x2000>;
+		interrupts = <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>;
+		interrupt-controller;
+		#interrupt-cells = <3>;
+	};
+
+	timer {
+		compatible = "arm,armv7-timer";
+		interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+			     <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+			     <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+			     <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>;
+	};
+
+	pmu {
+		compatible = "arm,cortex-a7-pmu";
+		interrupts = <GIC_SPI 172 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-affinity = <&cpu0>, <&cpu1>;
+	};
+};
Signature · 1 line
2.35.5
#45 lore raw

Re: [RFC PATCH 16/17] arm: sunxi: add Allwinner T113s devicetree stub

Quoted 22 lines · 在 2022-12-06星期二的 00:45 +0000,Andre Przywara写道:

This adds the basic SoC .dtsi devicetree stub for the Allwinner T113s SoC. This shares a die with the Allwinner D1 SoC (with RISC-V cores), but uses two Cortex-A7 cores instead of the T-HEAD C906 RISC-V core.

Include the existing D1 devicetree stub, but add the ARM specific nodes,
like for the CPU, the arch timer and the GIC.

---
 arch/arm/dts/sun8i-t113s.dtsi | 59
+++++++++++++++++++++++++++++++++++

 1 file changed, 59 insertions(+)

 create mode 100644 arch/arm/dts/sun8i-t113s.dtsi

arch/arm/dts/sun8i- renamed from arch/arm/dts/sun8i-t113s.dtsi +0 -0

t113s.dtsi
new file mode 100644
index 00000000000..0919ce559f6

arch/arm/dts/sun8i-t113s.dtsi line 7

Quoted 7 lines
arch/arm/dts/sun8i-t113s.dtsi new file +7 -0
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2022 Arm Ltd.
+
+#define SOC_PERIPHERAL_IRQ(nr) GIC_SPI nr
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <../../riscv/dts/sunxi-d1s-t113.dtsi>

Should we make a R528 DTSI which includes d1-t113.dtsi, and then T113 DTSI which includes d1s-t113.dtsi ?

Quoted 57 lines
arch/arm/dts/sun8i-t113s.dtsi new file +33 -0
+#include <../../riscv/dts/sunxi-d1-t113.dtsi>
+
+/ {
+       interrupt-parent = <&gic>;
+
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               cpu0: cpu@0 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <0>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+
+               cpu1: cpu@1 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <1>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+       };
+
+       gic: interrupt-controller@1c81000 {
+               compatible = "arm,gic-400";
+               reg = <0x03021000 0x1000>,
+                     <0x03022000 0x2000>,
+                     <0x03024000 0x2000>,
+                     <0x03026000 0x2000>;
+               interrupts = <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(4) |

IRQ_TYPE_LEVEL_HIGH)>;
+               interrupt-controller;
+               #interrupt-cells = <3>;
+       };
+
+       timer {
+               compatible = "arm,armv7-timer";
+               interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>;
+       };

arch/arm/dts/sun8i-t113s.dtsi new file +8 -0
+
+       pmu {
+               compatible = "arm,cortex-a7-pmu";
+               interrupts = <GIC_SPI 172 IRQ_TYPE_LEVEL_HIGH>,
+                            <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>;
+               interrupt-affinity = <&cpu0>, <&cpu1>;
+       };
+};
#46 lore raw

Re: [RFC PATCH 16/17] arm: sunxi: add Allwinner T113s devicetree stub

On Tue, 06 Dec 2022 13:55:02 +0800
Icenowy Zheng <[email protected]> wrote:

Hi Icenowy,

Quoted 25 lines · 在 2022-12-06星期二的 00:45 +0000,Andre Przywara写道:
Quoted 24 lines

This adds the basic SoC .dtsi devicetree stub for the Allwinner T113s SoC. This shares a die with the Allwinner D1 SoC (with RISC-V cores), but uses two Cortex-A7 cores instead of the T-HEAD C906 RISC-V core.

Include the existing D1 devicetree stub, but add the ARM specific nodes,
like for the CPU, the arch timer and the GIC.

---
 arch/arm/dts/sun8i-t113s.dtsi | 59
+++++++++++++++++++++++++++++++++++

 1 file changed, 59 insertions(+)

 create mode 100644 arch/arm/dts/sun8i-t113s.dtsi

arch/arm/dts/sun8i- renamed from arch/arm/dts/sun8i-t113s.dtsi +0 -0

t113s.dtsi
new file mode 100644
index 00000000000..0919ce559f6

arch/arm/dts/sun8i-t113s.dtsi new file +2 -0
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2022 Arm Ltd.
Quoted 8 lines

arch/arm/dts/sun8i-t113s.dtsi line 7

Quoted 5 lines
arch/arm/dts/sun8i-t113s.dtsi new file +5 -0
+
+#define SOC_PERIPHERAL_IRQ(nr) GIC_SPI nr
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <../../riscv/dts/sunxi-d1s-t113.dtsi>  

Should we make a R528 DTSI which includes d1-t113.dtsi, and then T113 DTSI which includes d1s-t113.dtsi ?

If I understand Samuel correctly, the T113-s includes the DSP, in contrast to the D1s, which has fused that off.
That would make including both sunxi-d1*-t113.dtsi files the right choice, wouldn't it? According to Samuel's list, sunxi-d1-t113.dtsi contains DSP related peripherals.

I don't know if there is anything DT relevant that the R528 has over the T113-s, but I don't claim to provide an R528 DT anyway, at least not yet, so we can leave this for the future, should a board or manual emerge.

So this file here should to be the equivalent of sun20i-d1s.dtsi, providing the ARM specific bits.

Does that make sense? If you agree, I would post this to Linux ASAP.

Cheers,
Andre

Quoted 58 lines
Quoted 57 lines
arch/arm/dts/sun8i-t113s.dtsi new file +33 -0
+#include <../../riscv/dts/sunxi-d1-t113.dtsi>
+
+/ {
+       interrupt-parent = <&gic>;
+
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               cpu0: cpu@0 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <0>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+
+               cpu1: cpu@1 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <1>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+       };
+
+       gic: interrupt-controller@1c81000 {
+               compatible = "arm,gic-400";
+               reg = <0x03021000 0x1000>,
+                     <0x03022000 0x2000>,
+                     <0x03024000 0x2000>,
+                     <0x03026000 0x2000>;
+               interrupts = <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(4) |  

IRQ_TYPE_LEVEL_HIGH)>;
+               interrupt-controller;
+               #interrupt-cells = <3>;
+       };
+
+       timer {
+               compatible = "arm,armv7-timer";
+               interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>;
+       };

arch/arm/dts/sun8i-t113s.dtsi new file +8 -0
+
+       pmu {
+               compatible = "arm,cortex-a7-pmu";
+               interrupts = <GIC_SPI 172 IRQ_TYPE_LEVEL_HIGH>,
+                            <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>;
+               interrupt-affinity = <&cpu0>, <&cpu1>;
+       };
+};  
#47 lore raw

Re: [RFC PATCH 16/17] arm: sunxi: add Allwinner T113s devicetree stub

Quoted 43 lines · 在 2023-01-03星期二的 17:38 +0000,Andre Przywara写道:

On Tue, 06 Dec 2022 13:55:02 +0800
Icenowy Zheng <[email protected]> wrote:

Hi Icenowy,

Quoted 29 lines · 在 2022-12-06星期二的 00:45 +0000,Andre Przywara写道:
Quoted 28 lines

This adds the basic SoC .dtsi devicetree stub for the Allwinner T113s
SoC. This shares a die with the Allwinner D1 SoC (with RISC-V cores),
but uses two Cortex-A7 cores instead of the T-HEAD C906 RISC-V core.

Include the existing D1 devicetree stub, but add the ARM specific nodes,
like for the CPU, the arch timer and the GIC.

---
 arch/arm/dts/sun8i-t113s.dtsi | 59
+++++++++++++++++++++++++++++++++++

 1 file changed, 59 insertions(+)

 create mode 100644 arch/arm/dts/sun8i-t113s.dtsi

arch/arm/dts/sun8i- renamed from arch/arm/dts/sun8i-t113s.dtsi +0 -0

t113s.dtsi
new file mode 100644
index 00000000000..0919ce559f6

arch/arm/dts/sun8i-t113s.dtsi new file +3 -0
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: (GPL-2.0+ or MIT)
+// Copyright (C) 2022 Arm Ltd.
+
Quoted 8 lines

arch/arm/dts/sun8i-t113s.dtsi line 7

Quoted 4 lines
arch/arm/dts/sun8i-t113s.dtsi new file +4 -0
+#define SOC_PERIPHERAL_IRQ(nr) GIC_SPI nr
+
+#include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <../../riscv/dts/sunxi-d1s-t113.dtsi>  

Should we make a R528 DTSI which includes d1-t113.dtsi, and then T113
DTSI which includes d1s-t113.dtsi ?

Quoted 8 lines

If I understand Samuel correctly, the T113-s includes the DSP, in contrast
to the D1s, which has fused that off.
That would make including both sunxi-d1*-t113.dtsi files the right choice,
wouldn't it? According to Samuel's list, sunxi-d1-t113.dtsi contains DSP
related peripherals.

Okay, although I heard that the DSP is not fused off (because DSP RAM is used by BROM).

Quoted 11 lines

I don't know if there is anything DT relevant that the R528 has over the
T113-s, but I don't claim to provide an R528 DT anyway, at least not yet,
so we can leave this for the future, should a board or manual emerge.

So this file here should to be the equivalent of sun20i-d1s.dtsi, providing the ARM specific bits.

Does that make sense? If you agree, I would post this to Linux ASAP.

It sounds good.

Quoted 69 lines

Cheers,
Andre

Quoted 63 lines
Quoted 62 lines
arch/arm/dts/sun8i-t113s.dtsi new file +33 -0
+#include <../../riscv/dts/sunxi-d1-t113.dtsi>
+
+/ {
+       interrupt-parent = <&gic>;
+
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               cpu0: cpu@0 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <0>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+
+               cpu1: cpu@1 {
+                       compatible = "arm,cortex-a7";
+                       device_type = "cpu";
+                       reg = <1>;
+                       clocks = <&ccu CLK_CPUX>;
+                       clock-names = "cpu";
+               };
+       };
+
+       gic: interrupt-controller@1c81000 {
+               compatible = "arm,gic-400";
+               reg = <0x03021000 0x1000>,
+                     <0x03022000 0x2000>,
+                     <0x03024000 0x2000>,
+                     <0x03026000 0x2000>;
+               interrupts = <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(4)

|
IRQ_TYPE_LEVEL_HIGH)>;
+               interrupt-controller;
+               #interrupt-cells = <3>;
+       };
+
+       timer {
+               compatible = "arm,armv7-timer";
+               interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>,
+                            <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(4) |
IRQ_TYPE_LEVEL_LOW)>;
+       };

arch/arm/dts/sun8i-t113s.dtsi new file +8 -0
+
+       pmu {
+               compatible = "arm,cortex-a7-pmu";
+               interrupts = <GIC_SPI 172 IRQ_TYPE_LEVEL_HIGH>,
+                            <GIC_SPI 173 IRQ_TYPE_LEVEL_HIGH>;
+               interrupt-affinity = <&cpu0>, <&cpu1>;
+       };
+};  
#48 lore raw

RFC PATCH 17/17 sunxi: add preliminary MangoPi MQ-R board support

In reply to Andre Przywara

This includes a preliminary basic DT and a defconfig to get the board booted. Although there is some DRAM code based on some disassembly, it is not ready yet, so the SPL doesn't really work, and needs some help from awboot.

---
 arch/arm/dts/Makefile                     |  2 +
 arch/arm/dts/sun8i-t113s-mangopi-mq-r.dts | 54 +++++++++++++++++++++++
 configs/mangopi_mq_r_defconfig            | 12 +++++
 3 files changed, 68 insertions(+)
 create mode 100644 arch/arm/dts/sun8i-t113s-mangopi-mq-r.dts
 create mode 100644 configs/mangopi_mq_r_defconfig
arch/arm/dts/Makefile +2 -0
index 43951a7731e..602349b88ab 100644
@@ -694,6 +694,8 @@ dtb-$(CONFIG_MACH_SUN8I_V3S) += \
 	sun8i-s3-pinecube.dtb \
 	sun8i-v3-sl631-imx179.dtb \
 	sun8i-v3s-licheepi-zero.dtb
+dtb-$(CONFIG_MACH_SUN8I_R528) += \
+	sun8i-t113s-mangopi-mq-r.dtb
 dtb-$(CONFIG_MACH_SUN50I_H5) += \
 	sun50i-h5-bananapi-m2-plus.dtb \
 	sun50i-h5-emlid-neutis-n5-devboard.dtb \
arch/arm/dts/sun8i-t113s-mangopi-mq-r.dts new file +54 -0

54 lines not on this page · raw message

configs/mangopi_mq_r_defconfig new file +12 -0
new file mode 100644
index 00000000000..32b1449dc92
@@ -0,0 +1,12 @@
+CONFIG_ARM=y
+CONFIG_ARCH_SUNXI=y
+CONFIG_DEFAULT_DEVICE_TREE="sun8i-t113s-mangopi-mq-r"
+CONFIG_SUNXI_MINIMUM_DRAM_MB=128
+CONFIG_SPL=y
+CONFIG_MACH_SUN8I_R528=y
+CONFIG_MMC0_CD_PIN="PF6"
+# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
+CONFIG_SYS_MONITOR_LEN=786432
+# dummy values
+CONFIG_DRAM_CLK=600
+CONFIG_DRAM_ZQ=0
Signature · 1 line
2.35.5
#49 lore raw
In reply to Andre Przywara

Hi Andre,

Quoted 1 line · Andre Przywara

Please let me know if you have any opinions!

I believe I promised you last month I'd let you know once I had a build I'm happy with, and I'm pleased to say that I think I've reached that point. I'm running quite rapidly out of sharp edges to sand down, too.

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly
- DRAM coming up correctly
- SPL sets configured boot clock correctly
- SPI-NAND support (SPL and U-Boot proper)
- MMC support (SPL and U-Boot proper)
- SPL boot from FEL
- USB gadget support
- Ethernet MAC+PHY support
- I²C support *
- GPIO support (LEDs, buttons, misc. board management)
- reset working (requries CONFIG_SYSRESET unset, WDT key)
- PSCI, nonsec
- Able to boot Linux ;)

* Requires nonzero MVTWSI_CONTROL_CLEAR_IFLG for NCAT2, and a patch to the pinctrl driver to configure the proper mux function for my necessary pins.

I figured I'd share this list as a sort of checklist for your own work, too. The remainder of my efforts now will probably be focused on mainlining this stuff (let me know how else I can be of help), and then I'm afraid I'll have to disappear back downstream to the Turing Pi 2 development effort, but maybe our paths will cross again in the kernel lists. :)

Thank you greatly,
Sam

P.S. I figure the reason there aren't I²C function defs in the d1 pinctrl table already is because Allwinner tends to kick around the I²C mux values a lot and we would need a per-pin lookup table that would eat up too much valuable image space?

In an entirely JUST FOR FUN exercise to give myself a break from staring at datasheets/patches and do a "pure CS" coding challenge for a change, I came up with a terse encoding scheme for this table. Here is the size (in bits) for a selection of D1's functions (pin assignments harvested from Linux):

'emac': 50,
'i2c0': 101,
'i2c1': 64,
'i2c2': 109,
'i2c3': 91,
'mmc0': 23,
'mmc1': 23,
'mmc2': 20,
'spi0': 41,
'spi1': 48,
'uart0': 78,
'uart1': 87,
'uart2': 88,
'uart3': 102,
'uart4': 68,
'uart5': 66,

...and yes, it also identifies invalid pin assignments! I'd be willing to contribute something like this if there's big interest, but I figure needing to compress this at build-time might be a bit too complicated for the U-Boot project's liking.

#50 lore raw

On Fri, 9 Jun 2023 16:16:43 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 6 lines · Andre Przywara
Quoted 1 line

Please let me know if you have any opinions!

I believe I promised you last month I'd let you know once I had a build I'm happy with, and I'm pleased to say that I think I've reached that point. I'm running quite rapidly out of sharp edges to sand down, too.

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Quoted 1 line

- Ethernet MAC+PHY support

Anything surprising here? Is that using an already supported external PHY?

Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?
For the WDT key: it seems like Linux got a nice patch to integrate this neatly into the driver without quirking this too much, do you have something ready for U-Boot as well? Would love to see it on the list then ;-)

Quoted 1 line

- PSCI, nonsec

ah yeah, owe you some reviews on this one ...

Quoted 5 lines

- Able to boot Linux ;)

* Requires nonzero MVTWSI_CONTROL_CLEAR_IFLG for NCAT2, and a patch to the pinctrl driver to configure the proper mux function for my necessary pins.

Are those pinmuxes straight forward to add to the pinctrl driver? Or are there conflicts similar to UART3?

Quoted 6 lines

I figured I'd share this list as a sort of checklist for your own work, too. The remainder of my efforts now will probably be focused on mainlining this stuff (let me know how else I can be of help), and then I'm afraid I'll have to disappear back downstream to the Turing Pi 2 development effort, but maybe our paths will cross again in the kernel lists. :)

Yeah, as you may know, the DT has to go through the kernel list. DT patches can be tedious to upstream, there is now much attention to every detail. Running checkpatch and dtbs_check should reveal most issues beforehand, though.

Cheers,
Andre

Quoted 36 lines

Thank you greatly,
Sam

P.S. I figure the reason there aren't I²C function defs in the d1 pinctrl table already is because Allwinner tends to kick around the I²C mux values a lot and we would need a per-pin lookup table that would eat up too much valuable image space?

In an entirely JUST FOR FUN exercise to give myself a break from staring at datasheets/patches and do a "pure CS" coding challenge for a change, I came up with a terse encoding scheme for this table. Here is the size (in bits) for a selection of D1's functions (pin assignments harvested from Linux):

'emac': 50,
'i2c0': 101,
'i2c1': 64,
'i2c2': 109,
'i2c3': 91,
'mmc0': 23,
'mmc1': 23,
'mmc2': 20,
'spi0': 41,
'spi1': 48,
'uart0': 78,
'uart1': 87,
'uart2': 88,
'uart3': 102,
'uart4': 68,
'uart5': 66,

...and yes, it also identifies invalid pin assignments! I'd be willing to contribute something like this if there's big interest, but I figure needing to compress this at build-time might be a bit too complicated for the U-Boot project's liking.

#51 lore raw

Hey Andre,

Quoted 4 lines · Andre Przywara

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Preeeeetttttyyy much everything I've changed locally has been submitted to the list or discussed in the relevant patchset. Have you updated your GitHub branch recently (past couple of weeks)? I haven't been watching it but I can pull it again and see which of my local changes are still required.

Quoted 5 lines
Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Actually no, my board's UART3 is on PB6/PB7, nice and standard.

Quoted 4 lines
Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Yep, everything was working satisfactorily once I figured out I needed to set CONFIG_SYS_CLK_FREQ to get acceptable boot speeds.

Quoted 3 lines
Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Yes, with Icenowy's series (322733).

I learned that the BROM sets the boot medium code to 0x04 when it's an SPI-*NAND* (while older chips used 0x03 for "it's either SPI-NOR or SPI-NAND, good luck figuring out which"). Since env_get_location assumes BOOT_DEVICE_SPI is NOR (and my target needs to load env from UBI iff booting from NAND), I'm hoping I can convince Icenowy to separate out the SPI-NAND and SPI-NOR load methods entirely (vs. her current try-NAND-then-NOR approach) with the aid of some disambiguation logic to probe for an SPI-NAND on the older chips known to report these as 0x03.

I also needed Maksim's patch series (355747) to support the D1 SPI master.

Quoted 4 lines
Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Yes and yes. I was just confirming they're good; no local work needed from me here.

Quoted 6 lines
Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Yes, with corrected SUNXI_SRAMC_BASE -- though I also needed my patches to make musb-new/sunxi.c use the UDC gadget model in DM (series 358842), as I don't think there's another way to init the controller at runtime.

I can't say whether the endpoint limit is correct or that mUSB *host* operation works.

The USB PHY only required that CONFIG_PHY_SUN4I_USB be enabled. The correct compatible is already wired up. It does look like your PHY series drops the explicit requirement to set PHY_SUN4I_USB so that's better than what I was doing (adding a select directive under R528).

I can test your series if you want but I doubt it intersects my work here in any significant way.

Quoted 4 lines
Quoted 1 line

- Ethernet MAC+PHY support

Anything surprising here? Is that using an already supported external PHY?

The only surprise was this was how I noticed that CONFIG_CLK_SUN20I_D1 was not being implicitly enabled. Enabling that was then how I found that the clock driver wasn't compatible with current upstream (which I already mentioned).

The PHY is external and already supported, adding it to my DT required very little work.

Quoted 5 lines
Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

GPIO is completely OotB, yes. I²C is OotB once MVTWSI_CONTROL_CLEAR_IFLG is set correctly. (The pinctrl requirements for it are a little harder, more on that below.)

Quoted 4 lines
Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?

Unsetting it is required for reset_cpu() to be defined. Your patchset updates that function (albeit without adding the WDT key, so the current patch is broken) to support NCAT2 already. U-Boot has no driver for "allwinner,sun20i-d1-wdt-reset", so this is the only way for reset to work.

Quoted 4 lines

For the WDT key: it seems like Linux got a nice patch to integrate this neatly into the driver without quirking this too much, do you have something ready for U-Boot as well? Would love to see it on the list then ;-)

I just hacked the correct value into the function; nothing really suitable for the list, sorry.

Quoted 3 lines
Quoted 1 line

- PSCI, nonsec

ah yeah, owe you some reviews on this one ...

It occurs to me that my work *might* support H6 as well (they both use CPUX blocks, right?) so perhaps it would be better if I de-RFC'd my series and instead worked to upstream it chasing H6, for you to come along later and tack on NCAT2 support with your R528 patchset?

Quoted 8 lines
Quoted 5 lines

- Able to boot Linux ;)

* Requires nonzero MVTWSI_CONTROL_CLEAR_IFLG for NCAT2, and a patch to the pinctrl driver to configure the proper mux function for my necessary pins.

Are those pinmuxes straight forward to add to the pinctrl driver? Or are there conflicts similar to UART3?

The conflict is that I'm on i2c2 + muxval 2. I suspect this one's going to be a downstream patch to add the necessary line:
{ "i2c2", 2 }, /* PE12-PE13 */

...and since no other assignment for i2c2 uses muxval 2, the only hope for this to be supported upstream would be for the pinctrl driver to include the full pin->muxval LUT.

Quoted 11 lines
Quoted 6 lines

I figured I'd share this list as a sort of checklist for your own work, too. The remainder of my efforts now will probably be focused on mainlining this stuff (let me know how else I can be of help), and then I'm afraid I'll have to disappear back downstream to the Turing Pi 2 development effort, but maybe our paths will cross again in the kernel lists. :)

Yeah, as you may know, the DT has to go through the kernel list. DT patches can be tedious to upstream, there is now much attention to every detail. Running checkpatch and dtbs_check should reveal most issues beforehand, though.

At this time I have no interest in upstreaming the DT. That might change in the future, but for now it's very much meant to be out-of-tree.

Quoted 2 lines

Cheers,
Andre

Likewise,
Sam

#52 lore raw

On Mon, 12 Jun 2023 15:18:17 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

Quoted 11 lines · Andre Przywara
Quoted 4 lines

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Preeeeetttttyyy much everything I've changed locally has been submitted to the list or discussed in the relevant patchset. Have you updated your GitHub branch recently (past couple of weeks)? I haven't been watching it but I can pull it again and see which of my local changes are still required.

So I finally found some time to address some issues in the series, especially in the first patches (pinctrl rework and preparation). I pushed a branch to https://github.com/apritzel/u-boot/commits/r528-rc
I need to do more testing, most importantly regression testing on other SoCs, and will only be able to post something next week, I guess.

If you could briefly list the things that are still missing, I could try to pick some low hanging fruits.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Actually no, my board's UART3 is on PB6/PB7, nice and standard.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Yep, everything was working satisfactorily once I figured out I needed to set CONFIG_SYS_CLK_FREQ to get acceptable boot speeds.

Interesting, indeed this is left at 0, which I think will result in 288 MHz. What is that frequency in your case? Do you know what the BSP programs? Traditionally we used something conservative that works without cooling and with the default voltage, but I don't know that value for the T113s.

Quoted 36 lines
Quoted 3 lines
Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Yes, with Icenowy's series (322733).

I learned that the BROM sets the boot medium code to 0x04 when it's an SPI-*NAND* (while older chips used 0x03 for "it's either SPI-NOR or SPI-NAND, good luck figuring out which"). Since env_get_location assumes BOOT_DEVICE_SPI is NOR (and my target needs to load env from UBI iff booting from NAND), I'm hoping I can convince Icenowy to separate out the SPI-NAND and SPI-NOR load methods entirely (vs. her current try-NAND-then-NOR approach) with the aid of some disambiguation logic to probe for an SPI-NAND on the older chips known to report these as 0x03.

I also needed Maksim's patch series (355747) to support the D1 SPI master.

Quoted 4 lines
Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Yes and yes. I was just confirming they're good; no local work needed from me here.

Quoted 6 lines
Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Yes, with corrected SUNXI_SRAMC_BASE -- though I also needed my patches to make musb-new/sunxi.c use the UDC gadget model in DM (series 358842), as I don't think there's another way to init the controller at runtime.

Quoted 7 lines

I can't say whether the endpoint limit is correct or that mUSB *host* operation works.

The USB PHY only required that CONFIG_PHY_SUN4I_USB be enabled. The correct compatible is already wired up. It does look like your PHY series drops the explicit requirement to set PHY_SUN4I_USB so that's better than what I was doing (adding a select directive under R528).

Ah, right, we already merged the "allwinner,sun20i-d1-usb-phy" patch.

Quoted 5 lines

I can test your series if you want but I doubt it intersects my work here in any significant way.

Quoted 2 lines
Quoted 1 line

- Ethernet MAC+PHY support

Quoted 7 lines
Quoted 2 lines

Anything surprising here? Is that using an already supported external PHY?

The only surprise was this was how I noticed that CONFIG_CLK_SUN20I_D1 was not being implicitly enabled. Enabling that was then how I found that the clock driver wasn't compatible with current upstream (which I already mentioned).

I think CLK_SUN20I_D1 should be set by default now, so can you check that this is fixed?

Quoted 15 lines

The PHY is external and already supported, adding it to my DT required very little work.

Quoted 5 lines
Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

GPIO is completely OotB, yes. I²C is OotB once MVTWSI_CONTROL_CLEAR_IFLG is set correctly. (The pinctrl requirements for it are a little harder, more on that below.)

Quoted 2 lines
Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Quoted 8 lines
Quoted 2 lines

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?

Unsetting it is required for reset_cpu() to be defined. Your patchset updates that function (albeit without adding the WDT key, so the current patch is broken) to support NCAT2 already. U-Boot has no driver for "allwinner,sun20i-d1-wdt-reset", so this is the only way for reset to work.

OK, thanks, need to dig into this again.

Quoted 8 lines
Quoted 4 lines

For the WDT key: it seems like Linux got a nice patch to integrate this neatly into the driver without quirking this too much, do you have something ready for U-Boot as well? Would love to see it on the list then ;-)

I just hacked the correct value into the function; nothing really suitable for the list, sorry.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

- PSCI, nonsec

ah yeah, owe you some reviews on this one ...

It occurs to me that my work *might* support H6 as well (they both use CPUX blocks, right?) so perhaps it would be better if I de-RFC'd my series and instead worked to upstream it chasing H6, for you to come along later and tack on NCAT2 support with your R528 patchset?

Why would we need H6 PSCI support? On the ARMv8 parts we use Trusted Firmware-A (TF-A) to provide PSCI services, which has a much more mature implementation.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

- Able to boot Linux ;)

* Requires nonzero MVTWSI_CONTROL_CLEAR_IFLG for NCAT2, and a patch to the pinctrl driver to configure the proper mux function for my necessary pins.

Quoted 6 lines
Quoted 2 lines

Are those pinmuxes straight forward to add to the pinctrl driver? Or are there conflicts similar to UART3?

The conflict is that I'm on i2c2 + muxval 2. I suspect this one's going to be a downstream patch to add the necessary line:
{ "i2c2", 2 }, /* PE12-PE13 */

How would this conflict, exactly? I don't see any other I2C2 definition? And what do you need I2C2 for, exactly?

Quoted 3 lines

...and since no other assignment for i2c2 uses muxval 2, the only hope for this to be supported upstream would be for the pinctrl driver to include the full pin->muxval LUT.

Well, there are shortcuts. I sketched some simpler idea in the comment at the top of pinctrl-sunxi.c.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

I figured I'd share this list as a sort of checklist for your own work, too. The remainder of my efforts now will probably be focused on mainlining this stuff (let me know how else I can be of help), and then I'm afraid I'll have to disappear back downstream to the Turing Pi 2 development effort, but maybe our paths will cross again in the kernel lists. :)

Quoted 6 lines
Quoted 4 lines

Yeah, as you may know, the DT has to go through the kernel list. DT patches can be tedious to upstream, there is now much attention to every detail. Running checkpatch and dtbs_check should reveal most issues beforehand, though.

At this time I have no interest in upstreaming the DT.

Why not?

Quoted 2 lines

That might change
in the future, but for now it's very much meant to be out-of-tree.

Why is this? This only increases your update burden, and we might break something and not realise that, if your DT is not in the tree. The question to ask should be rather: why *not* to upstream the DT? Please keep in mind that this would block U-Boot support, since we need the DT approved in the kernel before we could merge it into U-Boot.

Cheers,
Andre

#53 lore raw

Hi Andre,

Quoted 8 lines · Andre Przywara

So I finally found some time to address some issues in the series, especially in the first patches (pinctrl rework and preparation). I pushed a branch to https://github.com/apritzel/u-boot/commits/r528-rc
I need to do more testing, most importantly regression testing on other SoCs, and will only be able to post something next week, I guess.

If you could briefly list the things that are still missing, I could try to pick some low hanging fruits.

Rebasing onto this branch ended up eliminating a good chunk of my local hack commits. I've verified that everything is still working (but have not yet retested NAND SPL).

The remaining local changes I have are two additions to cpu_sunxi_ncat2.h:
+#define SUNXI_R_CPUCFG_BASE 0x07000400 /* for PSCI */
+#define SUNXI_RTC_BASE 0x07090000 /* for FEL */

The former can probably be brought into my PSCI series somehow (unless we expect more chips with CPUX blocks which might move those soft entry registers around, then it should be defined in cpu_sunxi_*.h). The latter is to support a reimplementation of Allwinner's efex command that I'm using for development (it pokes the magic number 0x5AA5A55A into RTC's GP_DATA_REG[2] and then resets; SPL clears that magic number and then does an early branch to BROM+0x0020 -- exactly what Allwinner's fork does).

I've also noticed exactly(!) one formatting difference in our clk_d1.c:
- .num_gates = ARRAY_SIZE(d1_gates),
+ .num_gates = ARRAY_SIZE(d1_gates),

Up to you if you prefer to align the = or not, but it does look inconsistent when .gates and .resets are aligned and .num_* aren't - might be a nitpick that comes up in patch review.

Quoted 2 lines

Interesting, indeed this is left at 0, which I think will result in 288 MHz.

Correct, at least that's what I was seeing.

Quoted 2 lines

What is that frequency in your case? Do you know what the BSP programs?

1008 MHz, both.

Quoted 3 lines

Traditionally we used something conservative that works without cooling and with the default voltage, but I don't know that value for the T113s.

For what it's worth, this board has a bare T113-s3 and the current OS does not reclock from 1008 MHz at all, and I don't know of any users of the board having stability issues.

In my own case, it idles at that clock at around ~35°C.

Quoted 2 lines

I think CLK_SUN20I_D1 should be set by default now, so can you check that this is fixed?

It is now gone from my defconfig and still working, so indeed this is fixed.

Quoted 3 lines

Why would we need H6 PSCI support? On the ARMv8 parts we use Trusted Firmware-A (TF-A) to provide PSCI services, which has a much more mature implementation.

It's not about the H6 and more about me being unsure whether R528/T113 is the first ARMv7-based SoC to use the new CPU management registers. If it's not, and there's another such chip supported in U-Boot that just lacks PSCI, it would make more sense for me to land my PSCI series independently of our work here, and then you can add the R528 case later. It sounds like R528/T113 may be the first such chip needing this new code, though, so this may have to wait until the R528 series lands.

Quoted 2 lines

How would this conflict, exactly? I don't see any other I2C2 definition?

Well, no, the other definitions haven't landed in U-Boot yet. But they do exist in the kernel, datasheets, and physical chips themselves:

PB0/PB1/PB8/PB9/PE4/PE5: i2c2 defined as muxval 4 PC0/PC1/PD20/PD21/PG6/PG7/PG14/PG15: i2c2 defined as muxval 3 PE12/PE13: i2c2 defined as muxval 2

Defining i2c2=2 universally would mean that the pins for i2c2 cannot be changed, since it would conflict with every other definition.

Quoted 1 line

And what do you need I2C2 for, exactly?

Pins PE12/PE13 host an I²C bus with the board ID EEPROM and an Ethernet switch that should be reset (and have a few registers set to configure proper port isolation) very shortly after power-on.

Quoted 2 lines

Well, there are shortcuts. I sketched some simpler idea in the comment at the top of pinctrl-sunxi.c.

My shortcut for the time being will probably be, "downstream patch."

Quoted 4 lines
Quoted 1 line

At this time I have no interest in upstreaming the DT.

Why not?

Quoted 8 lines
Quoted 2 lines

That might change
in the future, but for now it's very much meant to be out-of-tree.

Why is this? This only increases your update burden, and we might break something and not realise that, if your DT is not in the tree. The question to ask should be rather: why *not* to upstream the DT? Please keep in mind that this would block U-Boot support, since we need the DT approved in the kernel before we could merge it into U-Boot.

Currently, downstream is still fairly dependent on the Tina Linux kernel, not mainline. This is a situation I'd like to change, but it's a push for another day -- my focus right now is only on improving the bootloader situation.

This means that there are actually two DTs: one for the kernel, using the Tina Linux binding values, and one for U-Boot's control FDT, which can only support U-Boot right now (and cannot yet be tested on a real kernel). So neither DT is acceptable upstream: the former uses incompatible values/includes, and the latter isn't meant for Linux.

Even after(/if) this situation is resolved, the unified DT will probably remain in a state of flux for a while, until some drivers can be updated upstream (there's a slight mess with the I²C driver that needs to be cleaned up and we have to use GPIO-bitbanged I²C until then, for example) so it'll take more work before we have a "final" DT. At *that* time, upstreaming would be a good idea...

...but for now it's very much meant to be out-of-tree. :)

(I also do not work for the company that produced this board -- I'm just a contributor to the firmware project. Whether the project would even use the mainline version of its DT in the first place is, though likely, ultimately not my call.)

Quoted 2 lines

Cheers,
Andre

Likewise,
Sam

#54 lore raw

On Sun, 18 Jun 2023 13:01:33 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

thanks for the reply, that's very helpful.

Quoted 7 lines · Andre Przywara
Quoted 6 lines

So I finally found some time to address some issues in the series, especially in the first patches (pinctrl rework and preparation). I pushed a branch to https://github.com/apritzel/u-boot/commits/r528-rc
I need to do more testing, most importantly regression testing on other SoCs, and will only be able to post something next week, I guess.

Quoted 6 lines
Quoted 2 lines

If you could briefly list the things that are still missing, I could try to pick some low hanging fruits.

Rebasing onto this branch ended up eliminating a good chunk of my local hack commits. I've verified that everything is still working (but have not yet retested NAND SPL).

Great, thanks!

Review

Quoted 3 lines

The remaining local changes I have are two additions to cpu_sunxi_ncat2.h:

(quoted diff) +2 -0
+#define SUNXI_R_CPUCFG_BASE		0x07000400 /* for PSCI */
+#define SUNXI_RTC_BASE			0x07090000 /* for FEL */

Right, I will definitely take the PSCI bit, but not so sure about FEL yet.

Quoted 8 lines

The former can probably be brought into my PSCI series somehow (unless we expect more chips with CPUX blocks which might move those soft entry registers around, then it should be defined in cpu_sunxi_*.h). The latter is to support a reimplementation of Allwinner's efex command that I'm using for development (it pokes the magic number 0x5AA5A55A into RTC's GP_DATA_REG[2] and then resets; SPL clears that magic number and then does an early branch to BROM+0x0020 -- exactly what Allwinner's fork does).

So yeah, the request of a "Enter FEL" command came up multiple times, but so far no one could be bothered to implement this properly. The idea would be to have a generic command (more like "fel-reset" than efex), and allow each SoC (family) to implement this differently, as every SoC requires something a bit different here (32-bit vs. 64-bit, having an RTC vs not, etc).

If you could post your solution somewhere, we could start this effort. There was some patch for the H3 already, and it's relatively straight-forward on the newer SoCs (H616, IIRC), so if at least two popular, but different SoCs would be supported, we could make sure to have the right abstractions in place.

Quoted 7 lines

I've also noticed exactly(!) one formatting difference in our clk_d1.c:

(quoted diff) +1 -1
-	.num_gates = ARRAY_SIZE(d1_gates),
+	.num_gates  = ARRAY_SIZE(d1_gates),

Up to you if you prefer to align the = or not, but it does look inconsistent when .gates and .resets are aligned and .num_* aren't - might be a nitpick that comes up in patch review.

Well, this is how it is in all the other clock drivers, so I chose to stay consistent with them ;-)

Quoted 14 lines
Quoted 2 lines

Interesting, indeed this is left at 0, which I think will result in 288 MHz.

Correct, at least that's what I was seeing.

Quoted 2 lines

What is that frequency in your case? Do you know what the BSP programs?

1008 MHz, both.

Quoted 3 lines

Traditionally we used something conservative that works without cooling and with the default voltage, but I don't know that value for the T113s.

Quoted 5 lines

For what it's worth, this board has a bare T113-s3 and the current OS does not reclock from 1008 MHz at all, and I don't know of any users of the board having stability issues.

In my own case, it idles at that clock at around ~35°C.

OK, many thanks, it looks like 1008 MHz it is, then.

Quoted 23 lines
Quoted 2 lines

I think CLK_SUN20I_D1 should be set by default now, so can you check that this is fixed?

It is now gone from my defconfig and still working, so indeed this is fixed.

Quoted 3 lines

Why would we need H6 PSCI support? On the ARMv8 parts we use Trusted Firmware-A (TF-A) to provide PSCI services, which has a much more mature implementation.

It's not about the H6 and more about me being unsure whether R528/T113 is the first ARMv7-based SoC to use the new CPU management registers. If it's not, and there's another such chip supported in U-Boot that just lacks PSCI, it would make more sense for me to land my PSCI series independently of our work here, and then you can add the R528 case later. It sounds like R528/T113 may be the first such chip needing this new code, though, so this may have to wait until the R528 series lands.

Quoted 2 lines

How would this conflict, exactly? I don't see any other I2C2 definition?

Well, no, the other definitions haven't landed in U-Boot yet. But they do exist in the kernel, datasheets, and physical chips themselves:

Quoted 6 lines

PB0/PB1/PB8/PB9/PE4/PE5: i2c2 defined as muxval 4 PC0/PC1/PD20/PD21/PG6/PG7/PG14/PG15: i2c2 defined as muxval 3 PE12/PE13: i2c2 defined as muxval 2

Defining i2c2=2 universally would mean that the pins for i2c2 cannot be changed, since it would conflict with every other definition.

Well, we are well aware that the current pinmux code is limited, but we figured it does work for all practical purposes, and U-Boot has a far tighter scope than Linux, so we don't need to support every theoretically possible use case.
So if the TuringPi 2 board would be upstream, and you need I2C2, you would just set the precedence for muxval 2. It's then the next board's problem to live with that. Either by adding the port number (PB/PC/PD/PG) to the definitions, or by reverting to a DT solution:
https://lore.kernel.org/linux-sunxi/[email protected]/

Quoted 10 lines
Quoted 1 line

And what do you need I2C2 for, exactly?

Pins PE12/PE13 host an I²C bus with the board ID EEPROM and an Ethernet switch that should be reset (and have a few registers set to configure proper port isolation) very shortly after power-on.

Quoted 2 lines

Well, there are shortcuts. I sketched some simpler idea in the comment at the top of pinctrl-sunxi.c.

My shortcut for the time being will probably be, "downstream patch."

see below ;-)

Quoted 13 lines
Quoted 4 lines
Quoted 1 line

At this time I have no interest in upstreaming the DT.

Why not?

Quoted 8 lines
Quoted 2 lines

That might change
in the future, but for now it's very much meant to be out-of-tree.

Why is this? This only increases your update burden, and we might break something and not realise that, if your DT is not in the tree. The question to ask should be rather: why *not* to upstream the DT? Please keep in mind that this would block U-Boot support, since we need the DT approved in the kernel before we could merge it into U-Boot.

Quoted 4 lines

Currently, downstream is still fairly dependent on the Tina Linux kernel, not mainline. This is a situation I'd like to change, but it's a push for another day -- my focus right now is only on improving the bootloader situation.

Ah, depending on the BSP kernel is indeed quite bad. I wonder what features of the kernel you rely on that upstream does not have? Or is it more about the BMC userland parts that are married to the Allwinner kernel and its own interfaces?

Quoted 5 lines

This means that there are actually two DTs: one for the kernel, using the Tina Linux binding values, and one for U-Boot's control FDT, which can only support U-Boot right now (and cannot yet be tested on a real kernel). So neither DT is acceptable upstream: the former uses incompatible values/includes, and the latter isn't meant for Linux.

So as you probably know, conceptually there is only one DT per machine, as the DT describes the hardware. That's why try hard to align U-Boot and Linux at least, and IIUC the BSDs copied the version in the Linux kernel tree as well. Allwinner seems to have little clue or interest here, and we gave up on their (quite misguided) interpretation of the DT a long time ago.

Quoted 6 lines

Even after(/if) this situation is resolved, the unified DT will probably remain in a state of flux for a while, until some drivers can be updated upstream (there's a slight mess with the I²C driver that needs to be cleaned up and we have to use GPIO-bitbanged I²C until then, for example) so it'll take more work before we have a "final" DT. At *that* time, upstreaming would be a good idea...

Final DT is a noble goal, but in reality there will always be room for improvement and additions. So what we typically do is to start with a simple .dts for the kernel tree, describing the basic peripherals, and everything that already works and is not subject to debate. If in doubt, include a node, and we will comment. Could you prepare such a patch? This should not contradict any DT nodes that U-Boot uses, so it's not a double effort.
This would mean we have a *second* board DT for the T113s SoC in the kernel, which always helps to improve quality and prevents hacks that just work on the MangoPi. Besides, the TuringPi board is an actually useful application of the SoC, deployed and available, in contrast to just some development board from Chinese websites.
And once this is merged, we could just copy this over to U-Boot and add the defconfig and any other support patches there.

Quoted 3 lines

...but for now it's very much meant to be out-of-tree. :)

(I also do not work for the company that produced this board -- I'm just

Ah, that would have been a first anyway ;-)

Quoted 3 lines

a contributor to the firmware project. Whether the project would even use the mainline version of its DT in the first place is, though likely, ultimately not my call.)

Yeah, I understand it's not the most grateful job to chase up on doing things properly and stay on with the upstreaming process. Ultimately it's the right thing to do, though, and will save you hassle over time. Plus we (the community) will help you with that, and you'd get a second commit in the kernel ;-)

Cheers,
Andre

#55 lore raw

Hi Andre,

Quoted 7 lines · Andre Przywara

So yeah, the request of a "Enter FEL" command came up multiple times, but so far no one could be bothered to implement this properly. The idea would be to have a generic command (more like "fel-reset" than efex), and allow each SoC (family) to implement this differently, as every SoC requires something a bit different here (32-bit vs. 64-bit, having an RTC vs not, etc).

Quoted 5 lines

If you could post your solution somewhere, we could start this effort. There was some patch for the H3 already, and it's relatively straight-forward on the newer SoCs (H616, IIRC), so if at least two popular, but different SoCs would be supported, we could make sure to have the right abstractions in place.

I already have a "go_to_fel()" that does the right thing to enter FEL from the SPL; I would pretty much just need to introduce the following per-SoC(-family) functions:
- bool sunxi_fel_flag_test(void)
- void sunxi_fel_flag_clear(void)
- void sunxi_fel_flag_set(void)

The "fel-reset" command (which is easier to type than what I have, "run fel_do_enter") would then call sunxi_fel_flag_set() and initiate a reset, and the SPL's early init just has to do sunxi_fel_flag_test() -> sunxi_fel_flag_clear() -> go_to_fel(). Seems easy enough.

Could you recommend to me a sufficiently different chip to test my abstractions against? Something ARMv8 and *without* RTC? I can then send in a series adding FEL support for that. (Also, did that H3 patch actually land? I didn't see anything but want to know if I should be refactoring my approach to extend what that H3 patch does or not.)

Quoted 4 lines

Ah, depending on the BSP kernel is indeed quite bad. I wonder what features of the kernel you rely on that upstream does not have? Or is it more about the BMC userland parts that are married to the Allwinner kernel and its own interfaces?

I don't fully know; getting the kernel back on mainline is, as I said, a push for another day. I'm very much making a point of not looking into it before the bootloader can be upgraded to something that isn't a crashy, hard-to-update, failure-prone mess. (I'm working in "biggest fire, first out" order.)

That said, the first such dependent feature that leaps to mind is the AWNAND driver's CONFIG_AW_SPINAND_SIMULATE_MULTIPLANE, which logically interleaves pages of the NAND in a different ordering vs. what the physical NAND (and mainline's spi-nand driver) does. Alas this is a feature we're dependent on not because it provides benefits to our users (it does not, and in downstream discussions I've been soapboxing about how it's likely wearing down people's NANDs) but because the boards are flashed at the factory with this flag enabled so we need it set for the NAND to be accessible. We've experimented with reflashing the board with that flag disabled, but that has so far only resulted in corrupted flash.

Hope is not lost, though, for I have a half-written tool which shows some promise in being able to "unscramble the egg" and migrate existing NANDs over to the correct layout. That should be sufficient to get mainline U-Boot (and Tina Linux with the flag disabled) working, but I have no idea about mainline Linux still: this would only peel back one layer of the onion, and I don't know whether the next obstacle will be easier, harder, or about the same difficulty.

But it does mean that, for now, we're stuck with Tina Linux.

Quoted 5 lines

Final DT is a noble goal, but in reality there will always be room for improvement and additions. So what we typically do is to start with a simple .dts for the kernel tree, describing the basic peripherals, and everything that already works and is not subject to debate. If in doubt, include a node, and we will comment. Could you prepare such a patch?

The peripheral-describing .dts that I have is for Tina Linux, and uses incompatible compatibles (ha), includes, dt-bindings, temporary hacks while better driver support can be developed, and would otherwise not fly upstream. I can send it in *anyway* if for some reason you think that's a good idea, but I really don't see that as being anything other than a waste of time.

As well, I can't write a fresh .dts for mainline (one more likely to be accepted on the list). A mainline kernel has never been booted on this board, so I would do no better at this than a kernel contributor selected at random. The best I can do now is write something that *looks* like the correct .dts.

As I keep saying, that may change in the future. But the answer today is still "no, I cannot."

Quoted 3 lines

This
should not contradict any DT nodes that U-Boot uses, so it's not a double effort.

True, in theory it *shouldn't* but in practice, I've found it does.

One way I've been bitten is that the sunxi SPI driver in U-Boot doesn't support Quad-SPI, so if the DT says the SPI-NAND is connected with a bus width of 4, the SPI-NAND driver requests Quad-SPI transfers, but the SPI master driver has no idea that it needs to handle the transfer any differently, and we're left with corrupt NAND reads/writes. Without Quad-SPI support in U-Boot's master driver (and/or, better yet, a U-Boot equivalent to Linux commit 83596fbeb5) -- also a push for another day -- I have no choice but to give U-Boot a specially edited version of the DT that omits this property.

Quoted 7 lines

This would mean we have a *second* board DT for the T113s SoC in the kernel, which always helps to improve quality and prevents hacks that just work on the MangoPi. Besides, the TuringPi board is an actually useful application of the SoC, deployed and available, in contrast to just some development board from Chinese websites.
And once this is merged, we could just copy this over to U-Boot and add the defconfig and any other support patches there.

See below.

Quoted 5 lines
Quoted 3 lines

...but for now it's very much meant to be out-of-tree. :)

(I also do not work for the company that produced this board -- I'm just

Ah, that would have been a first anyway ;-)

Oh? What would have been a first? I could pass it along to my contact at this company and encourage him to get involved in some way. I'm sure they'd appreciate the opportunity for the good press associated with being the first at something in the F/OSS world, and it might help to get them in the habit of cooperating closely with upstream (to make it less likely that they just fork things the moment upstream doesn't solve some problem they're having).

Quoted 5 lines

Yeah, I understand it's not the most grateful job to chase up on doing things properly and stay on with the upstreaming process. Ultimately it's the right thing to do, though, and will save you hassle over time. Plus we (the community) will help you with that, and you'd get a second commit in the kernel ;-)

Ideologically-speaking, this is music to my ears, and I think we would even be having this same discussion were our roles reversed: we do both agree fully on the (mutual) benefits of upstream contribution.

But even more ultimately: the available time on any given day is limited, and I have to choose my battles. There are often things that either require less effort, save an even greater hassle over time, or provide more urgently-needed benefits, which (pragmatically speaking) ought to take priority. That doesn't mean the other lower-priority items have no benefit, it just means they should not be done *now.*

Quoted 2 lines

Cheers,
Andre

Likewise,
Sam

#56 lore raw

On Tue, 20 Jun 2023 16:11:48 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

pleasure to write with you ;-)

Quoted 14 lines · Andre Przywara
Quoted 7 lines

So yeah, the request of a "Enter FEL" command came up multiple times, but so far no one could be bothered to implement this properly. The idea would be to have a generic command (more like "fel-reset" than efex), and allow each SoC (family) to implement this differently, as every SoC requires something a bit different here (32-bit vs. 64-bit, having an RTC vs not, etc).

Quoted 5 lines

If you could post your solution somewhere, we could start this effort. There was some patch for the H3 already, and it's relatively straight-forward on the newer SoCs (H616, IIRC), so if at least two popular, but different SoCs would be supported, we could make sure to have the right abstractions in place.

Quoted 6 lines

I already have a "go_to_fel()" that does the right thing to enter FEL from the SPL; I would pretty much just need to introduce the following per-SoC(-family) functions:
- bool sunxi_fel_flag_test(void)
- void sunxi_fel_flag_clear(void)
- void sunxi_fel_flag_set(void)

Well, so this is actually the fallback implementation which should somewhat work on most SoCs: set a flag, reset, and catch the flag in the SPL. For modern SoCs with CPU hotplug support (the H616 is one one of those, and it looks like the T113s is as well), there is actually a more direct route:
We put some magic and the FEL entry address into some special memory locations, then just reset. Now the *BootROM* will do the check already, and branch to the provided entry point, which would be the FEL routine. This doesn't rely on a prepared SPL to be loaded, so works without a boot device with mainline U-Boot around.
Refer to section 3.4.2.3 and 3.4.2.4 of the T113-S3 user manual (v1.1). According to this, the magic would be 0xfa50392f, the magic's address is 0x070005C0, and CPU0's entry point address would be in 0x070005C4. I had a proof of concept implementation for the H616 using this method. The only problem left would be that someone needs to clean the magic afterwards, otherwise any follow-up reset would trigger FEL mode again.

Quoted 7 lines

The "fel-reset" command (which is easier to type than what I have, "run fel_do_enter") would then call sunxi_fel_flag_set() and initiate a reset, and the SPL's early init just has to do sunxi_fel_flag_test() -> sunxi_fel_flag_clear() -> go_to_fel(). Seems easy enough.

Could you recommend to me a sufficiently different chip to test my abstractions against? Something ARMv8 and *without* RTC?

I think all ARMv8 parts have an RTC, so your generic approach might work there as well. The complication is that the SPL switches to AArch64 very early, in hand-stitched AArch32 assembly, check out arch/arm/include/asm/arch-sunxi/boot0.h.
The check would need to be coded like this, then.

Quoted 4 lines

I can then send
in a series adding FEL support for that. (Also, did that H3 patch actually land? I didn't see anything but want to know if I should be refactoring my approach to extend what that H3 patch does or not.)

https://patchwork.ozlabs.org/project/uboot/patch/c211aa414c59e7275fef82bf6f0035276d6e29f3.1656875482.git.msuchanek@suse.de/

Another generic approach for ARMv7 parts would be to reset the peripherals as much as possible, then configure the core in a BROM compatible way (MMU off, etc) and just branch to the BROM FEL entry address. This idea is already somewhat used in our return-to-FEL code in the SPL, although we don't change too much of the core setup in the SPL.

Quoted 10 lines
Quoted 4 lines

Ah, depending on the BSP kernel is indeed quite bad. I wonder what features of the kernel you rely on that upstream does not have? Or is it more about the BMC userland parts that are married to the Allwinner kernel and its own interfaces?

I don't fully know; getting the kernel back on mainline is, as I said, a push for another day. I'm very much making a point of not looking into it before the bootloader can be upgraded to something that isn't a crashy, hard-to-update, failure-prone mess. (I'm working in "biggest fire, first out" order.)

Fair enough, from a mainlining point of view you need to funnel the board .dts through the Linux tree first, though.
Also, with the right DT, a mainline kernel would run on the board already, maybe just not with the full functionality you'd expect from it.

What I mean to say: you can surely continue using Tina Linux for the BMC functionality on the board right now, but still upstream the board .dts. As mentioned, the DT just describes the hardware, so it doesn't dictate what to do with it. One might abuse the board as a T113s dev board, maybe ;-) Does it work without any of the modules populated?

Quoted 27 lines

That said, the first such dependent feature that leaps to mind is the AWNAND driver's CONFIG_AW_SPINAND_SIMULATE_MULTIPLANE, which logically interleaves pages of the NAND in a different ordering vs. what the physical NAND (and mainline's spi-nand driver) does. Alas this is a feature we're dependent on not because it provides benefits to our users (it does not, and in downstream discussions I've been soapboxing about how it's likely wearing down people's NANDs) but because the boards are flashed at the factory with this flag enabled so we need it set for the NAND to be accessible. We've experimented with reflashing the board with that flag disabled, but that has so far only resulted in corrupted flash.

Hope is not lost, though, for I have a half-written tool which shows some promise in being able to "unscramble the egg" and migrate existing NANDs over to the correct layout. That should be sufficient to get mainline U-Boot (and Tina Linux with the flag disabled) working, but I have no idea about mainline Linux still: this would only peel back one layer of the onion, and I don't know whether the next obstacle will be easier, harder, or about the same difficulty.

But it does mean that, for now, we're stuck with Tina Linux.

Quoted 5 lines

Final DT is a noble goal, but in reality there will always be room for improvement and additions. So what we typically do is to start with a simple .dts for the kernel tree, describing the basic peripherals, and everything that already works and is not subject to debate. If in doubt, include a node, and we will comment. Could you prepare such a patch?

Quoted 4 lines

The peripheral-describing .dts that I have is for Tina Linux, and uses incompatible compatibles (ha), includes, dt-bindings, temporary hacks while better driver support can be developed, and would otherwise not fly upstream.

Sure, you keep that nasty piece downstream, and load it in U-Boot into $fdt_addr_r, then take it from there.
That doesn't affect the mainline Linux and U-Boot DT, though, which could be upstreamed independently.
Then you can use the mainline DT (as used by U-Boot), using $fdtcontroladdr, or any loaded DT, via $fdt_addr_r.

Quoted 3 lines

I can send it in *anyway* if for some reason you think that's a good idea, but I really don't see that as being anything other than a waste of time.

There is indeed no point in sending a DT which only works with the Allwinner BSP kernel.

Quoted 2 lines

As well, I can't write a fresh .dts for mainline (one more likely to be accepted on the list).

Yes, please!

Quoted 3 lines

A mainline kernel has never been booted on this
board, so I would do no better at this than a kernel contributor selected at random.

... having a board. So far you are the one contributor with access to the hardware, so: thanks for volunteering! ;-)

Quoted 1 line

The best I can do now is write something that *looks* like the correct .dts.

Yes, and that would be the right .dts, if it passes the kernel review.

Quoted 2 lines

As I keep saying, that may change in the future. But the answer today is still "no, I cannot."

So to summarise what I am trying to say: You create a simple .dts file, basically #include "sun8i-t113s.dtsi" and declaring the UART. Then add the devices that already work (Ethernet?, USB-OTG) and see how far you get. You could just load a kernel and initrd via FEL, and use the mainline kernel just via serial like this. Granted, this is not really useful in the BMC context, but would be a start.

This is actually similar to what Chris just did [1] for the RG Nano: this initial DT for this mini handheld gaming console has no display support, so is pretty useless in its original context, but starting mainline support is the important thing here.

Plus: this exposes the problems you face (PHY config?) to a wider range of people, who can help with the solution.

[1]
https://lore.kernel.org/linux-sunxi/[email protected]/T

Quoted 7 lines
Quoted 4 lines

This
should not contradict any DT nodes that U-Boot uses, so it's not a double effort.

True, in theory it *shouldn't* but in practice, I've found it does.

Quoted 9 lines

One way I've been bitten is that the sunxi SPI driver in U-Boot doesn't support Quad-SPI, so if the DT says the SPI-NAND is connected with a bus width of 4, the SPI-NAND driver requests Quad-SPI transfers, but the SPI master driver has no idea that it needs to handle the transfer any differently, and we're left with corrupt NAND reads/writes. Without Quad-SPI support in U-Boot's master driver (and/or, better yet, a U-Boot equivalent to Linux commit 83596fbeb5) -- also a push for another day -- I have no choice but to give U-Boot a specially edited version of the DT that omits this property.

The U-Boot build system support some kind of build time DT "overlay"
feature: You put a file with the same name, but ending in "-u-boot.dtsi" in the arch/arm/dts directory, and it will be included into the DT which gets embedded into the U-Boot image. See arch/arm/dts/sun50i-a64-sopine-baseboard-u-boot.dts for an example, and doc/develop/devicetree/control.rst for the proper documentation.
So we upstream a minimal, non-controversial and non-contradicting base .dts into the kernel tree, and can fix things up for the time being using this method. This hack can then go away if either the mainline kernel DT gets fixed and/or U-Boot learns the quad-SPI trick.

Quoted 10 lines
Quoted 7 lines

This would mean we have a *second* board DT for the T113s SoC in the kernel, which always helps to improve quality and prevents hacks that just work on the MangoPi. Besides, the TuringPi board is an actually useful application of the SoC, deployed and available, in contrast to just some development board from Chinese websites.
And once this is merged, we could just copy this over to U-Boot and add the defconfig and any other support patches there.

See below.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

...but for now it's very much meant to be out-of-tree. :)

(I also do not work for the company that produced this board -- I'm just

Ah, that would have been a first anyway ;-)

Oh? What would have been a first? I could pass it along to my contact at

Someone from the board vendor company actually actively adding upstream support for their device early. There were some examples in the past where employees participated in upstreaming, but I cannot remember seeing this too often when it comes to the initial DT support.

Quoted 6 lines

this company and encourage him to get involved in some way. I'm sure they'd appreciate the opportunity for the good press associated with being the first at something in the F/OSS world, and it might help to get them in the habit of cooperating closely with upstream (to make it less likely that they just fork things the moment upstream doesn't solve some problem they're having).

Yes, I understand the pressure in a product-centric world with release dates and timelines, but the advantage of vendor-backed contributions are early access to hardware and documentation, plus access to the hardware engineers.

Quoted 6 lines
Quoted 5 lines

Yeah, I understand it's not the most grateful job to chase up on doing things properly and stay on with the upstreaming process. Ultimately it's the right thing to do, though, and will save you hassle over time. Plus we (the community) will help you with that, and you'd get a second commit in the kernel ;-)

Quoted 6 lines

Ideologically-speaking, this is music to my ears, and I think we would even be having this same discussion were our roles reversed: we do both agree fully on the (mutual) benefits of upstream contribution.

But even more ultimately: the available time on any given day is limited, and I have to choose my battles. There are often things that

Fair enough, and there is no real pressure in getting the mainline DT fully functional and merged today. But we should start the process *now*, as this helps to detect problems early, and allows other people to jump on this and continue the work or help out.

Cheers,
Andre

Quoted 10 lines

either require less effort, save an even greater hassle over time, or provide more urgently-needed benefits, which (pragmatically speaking) ought to take priority. That doesn't mean the other lower-priority items have no benefit, it just means they should not be done *now.*

Quoted 2 lines

Cheers,
Andre

Likewise,
Sam

#57 lore raw
Quoted 6 lines · Andre Przywara

On Tue, 20 Jun 2023 16:11:48 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

pleasure to write with you ;-)

Hi Andre,

Likewise!

Quoted 5 lines

Well, so this is actually the fallback implementation which should somewhat work on most SoCs: set a flag, reset, and catch the flag in the SPL. For modern SoCs with CPU hotplug support (the H616 is one one of those, and it looks like the T113s is as well), there is actually a more direct route:

Oh man, I would definitely prefer a direct route that doesn't require the SPL coming up a second time, but...

Quoted 9 lines

We put some magic and the FEL entry address into some special memory locations, then just reset. Now the *BootROM* will do the check already, and branch to the provided entry point, which would be the FEL routine. This doesn't rely on a prepared SPL to be loaded, so works without a boot device with mainline U-Boot around.
Refer to section 3.4.2.3 and 3.4.2.4 of the T113-S3 user manual (v1.1). According to this, the magic would be 0xfa50392f, the magic's address is 0x070005C0, and CPU0's entry point address would be in 0x070005C4. I had a proof of concept implementation for the H616 using this method.

...I tried this and it seems that the 070005C* block hardware-resets to zero before BROM runs. Is there a softer reset method you had in mind that would avoid this?

Quoted 3 lines

The only
problem left would be that someone needs to clean the magic afterwards, otherwise any follow-up reset would trigger FEL mode again.

That's at least pretty fixable though: instead of setting the entry address to the FEL entry point, set it to a thunk placed in SRAM that clears the flag before continuing onward to FEL.

Quoted 14 lines
Quoted 7 lines

The "fel-reset" command (which is easier to type than what I have, "run fel_do_enter") would then call sunxi_fel_flag_set() and initiate a reset, and the SPL's early init just has to do sunxi_fel_flag_test() -> sunxi_fel_flag_clear() -> go_to_fel(). Seems easy enough.

Could you recommend to me a sufficiently different chip to test my abstractions against? Something ARMv8 and *without* RTC?

I think all ARMv8 parts have an RTC, so your generic approach might work there as well. The complication is that the SPL switches to AArch64 very early, in hand-stitched AArch32 assembly, check out arch/arm/include/asm/arch-sunxi/boot0.h.
The check would need to be coded like this, then.

Quoted 6 lines
Quoted 4 lines

I can then send
in a series adding FEL support for that. (Also, did that H3 patch actually land? I didn't see anything but want to know if I should be refactoring my approach to extend what that H3 patch does or not.)

https://patchwork.ozlabs.org/project/uboot/patch/c211aa414c59e7275fef82bf6f0035276d6e29f3.1656875482.git.msuchanek@suse.de/

This approach seems close to mine, only my go_to_fel() enters by way of return_to_fel() after first modifying fel_stash.lr, since the return_to_fel() mechanism already takes care of restoring the core to a BROM-friendly state.

Quoted 2 lines

One might abuse the board as a T113s dev
board, maybe ;-) Does it work without any of the modules populated?

Sure, if you're thinking about getting one. You just need an ATX-pinout PSU to power the BMC (it runs off of the 5V standby rail).

Quoted 2 lines

... having a board. So far you are the one contributor with access to the hardware, so: thanks for volunteering! ;-)

Andre, please, I know you're being tongue-in-cheek here, but I said "no." We should have reached the agree-to-disagree point 2 emails ago: you've made your (very compelling) case for why downstream would benefit from the early expertise of the upstream DT reviewers, and how upstream would benefit from having the DT for a second "real" T113-using board, but at some point you need to trust that I understand that and that I must therefore have very good reasons not to be distracting myself with trying to (dual-)boot a mainline kernel yet. One thing at a time, y'know? :)

Quoted 11 lines

The U-Boot build system support some kind of build time DT "overlay"
feature: You put a file with the same name, but ending in "-u-boot.dtsi" in the arch/arm/dts directory, and it will be included into the DT which gets embedded into the U-Boot image. See arch/arm/dts/sun50i-a64-sopine-baseboard-u-boot.dts for an example, and doc/develop/devicetree/control.rst for the proper documentation.
So we upstream a minimal, non-controversial and non-contradicting base .dts into the kernel tree, and can fix things up for the time being using this method. This hack can then go away if either the mainline kernel DT gets fixed and/or U-Boot learns the quad-SPI trick.

Oh, good to know! I'll try to remember that this option exists when the time comes to use it.

Quoted 4 lines

Someone from the board vendor company actually actively adding upstream support for their device early. There were some examples in the past where employees participated in upstreaming, but I cannot remember seeing this too often when it comes to the initial DT support.

I brought this email thread to the attention of the firmware development team at this company, then. No promises (they seem to have their hands sufficiently full with userspace work) but FWIW my opinion of them is that they do have a community-centric and F/OSS-oriented mindset, so with a bit of luck they may make themselves known on the upstream mailing lists at some point.

Thank you for your ongoing efforts,
Sam

#58 lore raw
In reply to Sam Edwards

On Mon, 12 Jun 2023 15:18:17 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

something regarding "reset" below ...

Quoted 100 lines · Andre Przywara
Quoted 4 lines

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Preeeeetttttyyy much everything I've changed locally has been submitted to the list or discussed in the relevant patchset. Have you updated your GitHub branch recently (past couple of weeks)? I haven't been watching it but I can pull it again and see which of my local changes are still required.

Quoted 5 lines
Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Actually no, my board's UART3 is on PB6/PB7, nice and standard.

Quoted 4 lines
Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Yep, everything was working satisfactorily once I figured out I needed to set CONFIG_SYS_CLK_FREQ to get acceptable boot speeds.

Quoted 3 lines
Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Yes, with Icenowy's series (322733).

I learned that the BROM sets the boot medium code to 0x04 when it's an SPI-*NAND* (while older chips used 0x03 for "it's either SPI-NOR or SPI-NAND, good luck figuring out which"). Since env_get_location assumes BOOT_DEVICE_SPI is NOR (and my target needs to load env from UBI iff booting from NAND), I'm hoping I can convince Icenowy to separate out the SPI-NAND and SPI-NOR load methods entirely (vs. her current try-NAND-then-NOR approach) with the aid of some disambiguation logic to probe for an SPI-NAND on the older chips known to report these as 0x03.

I also needed Maksim's patch series (355747) to support the D1 SPI master.

Quoted 4 lines
Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Yes and yes. I was just confirming they're good; no local work needed from me here.

Quoted 6 lines
Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Yes, with corrected SUNXI_SRAMC_BASE -- though I also needed my patches to make musb-new/sunxi.c use the UDC gadget model in DM (series 358842), as I don't think there's another way to init the controller at runtime.

I can't say whether the endpoint limit is correct or that mUSB *host* operation works.

The USB PHY only required that CONFIG_PHY_SUN4I_USB be enabled. The correct compatible is already wired up. It does look like your PHY series drops the explicit requirement to set PHY_SUN4I_USB so that's better than what I was doing (adding a select directive under R528).

I can test your series if you want but I doubt it intersects my work here in any significant way.

Quoted 4 lines
Quoted 1 line

- Ethernet MAC+PHY support

Anything surprising here? Is that using an already supported external PHY?

The only surprise was this was how I noticed that CONFIG_CLK_SUN20I_D1 was not being implicitly enabled. Enabling that was then how I found that the clock driver wasn't compatible with current upstream (which I already mentioned).

The PHY is external and already supported, adding it to my DT required very little work.

Quoted 5 lines
Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

GPIO is completely OotB, yes. I²C is OotB once MVTWSI_CONTROL_CLEAR_IFLG is set correctly. (The pinctrl requirements for it are a little harder, more on that below.)

Quoted 2 lines
Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Quoted 8 lines
Quoted 2 lines

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?

Unsetting it is required for reset_cpu() to be defined. Your patchset updates that function (albeit without adding the WDT key, so the current patch is broken) to support NCAT2 already. U-Boot has no driver for "allwinner,sun20i-d1-wdt-reset", so this is the only way for reset to work.

So I had a look at this, and it's a bit surprising:
The watchdog driver already supports "allwinner,sun20i-d1-wdt" for a while. We don't need to list the "-reset" version, because the normal compatible name acts as a fallback string. However the DT node in the base .dtsi sets: status = "reserved"; for this (and the other) watchdog, so U-Boot's DM (correctly!) ignores those devices. Trying to figure out why. Adding:

&wdt {
	status = "okay";
};

to sun8i-t113s.dtsi fixes that for me, now the reset command works.

Quoted 7 lines
Quoted 4 lines

For the WDT key: it seems like Linux got a nice patch to integrate this neatly into the driver without quirking this too much, do you have something ready for U-Boot as well? Would love to see it on the list then ;-)

I just hacked the correct value into the function; nothing really suitable for the list, sorry.

CONFIG_SYSRESET is only applicable for U-Boot proper, so we need reset_cpu for the SPL still. That is not as critical, since the SPL resets the board only in case of an error, but should be fixed nevertheless. I will have a stab at this.

Cheers,
Andre

Quoted 46 lines
Quoted 3 lines
Quoted 1 line

- PSCI, nonsec

ah yeah, owe you some reviews on this one ...

It occurs to me that my work *might* support H6 as well (they both use CPUX blocks, right?) so perhaps it would be better if I de-RFC'd my series and instead worked to upstream it chasing H6, for you to come along later and tack on NCAT2 support with your R528 patchset?

Quoted 8 lines
Quoted 5 lines

- Able to boot Linux ;)

* Requires nonzero MVTWSI_CONTROL_CLEAR_IFLG for NCAT2, and a patch to the pinctrl driver to configure the proper mux function for my necessary pins.

Are those pinmuxes straight forward to add to the pinctrl driver? Or are there conflicts similar to UART3?

The conflict is that I'm on i2c2 + muxval 2. I suspect this one's going to be a downstream patch to add the necessary line:
{ "i2c2", 2 }, /* PE12-PE13 */

...and since no other assignment for i2c2 uses muxval 2, the only hope for this to be supported upstream would be for the pinctrl driver to include the full pin->muxval LUT.

Quoted 11 lines
Quoted 6 lines

I figured I'd share this list as a sort of checklist for your own work, too. The remainder of my efforts now will probably be focused on mainlining this stuff (let me know how else I can be of help), and then I'm afraid I'll have to disappear back downstream to the Turing Pi 2 development effort, but maybe our paths will cross again in the kernel lists. :)

Yeah, as you may know, the DT has to go through the kernel list. DT patches can be tedious to upstream, there is now much attention to every detail. Running checkpatch and dtbs_check should reveal most issues beforehand, though.

At this time I have no interest in upstreaming the DT. That might change in the future, but for now it's very much meant to be out-of-tree.

Quoted 2 lines

Cheers,
Andre

Likewise,
Sam

#59 lore raw

Hi Andre, Sam,

пт, 16 июн. 2023 г. в 18:59, Andre Przywara <[email protected]>:

Quoted 124 lines

On Mon, 12 Jun 2023 15:18:17 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

something regarding "reset" below ...

Quoted 100 lines · Andre Przywara
Quoted 4 lines

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Preeeeetttttyyy much everything I've changed locally has been submitted to the list or discussed in the relevant patchset. Have you updated your GitHub branch recently (past couple of weeks)? I haven't been watching it but I can pull it again and see which of my local changes are still required.

Quoted 5 lines
Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Actually no, my board's UART3 is on PB6/PB7, nice and standard.

Quoted 4 lines
Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Yep, everything was working satisfactorily once I figured out I needed to set CONFIG_SYS_CLK_FREQ to get acceptable boot speeds.

Quoted 3 lines
Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Yes, with Icenowy's series (322733).

I learned that the BROM sets the boot medium code to 0x04 when it's an SPI-*NAND* (while older chips used 0x03 for "it's either SPI-NOR or SPI-NAND, good luck figuring out which"). Since env_get_location assumes BOOT_DEVICE_SPI is NOR (and my target needs to load env from UBI iff booting from NAND), I'm hoping I can convince Icenowy to separate out the SPI-NAND and SPI-NOR load methods entirely (vs. her current try-NAND-then-NOR approach) with the aid of some disambiguation logic to probe for an SPI-NAND on the older chips known to report these as 0x03.

I also needed Maksim's patch series (355747) to support the D1 SPI master.

Quoted 4 lines
Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Yes and yes. I was just confirming they're good; no local work needed from me here.

Quoted 6 lines
Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Yes, with corrected SUNXI_SRAMC_BASE -- though I also needed my patches to make musb-new/sunxi.c use the UDC gadget model in DM (series 358842), as I don't think there's another way to init the controller at runtime.

I can't say whether the endpoint limit is correct or that mUSB *host* operation works.

The USB PHY only required that CONFIG_PHY_SUN4I_USB be enabled. The correct compatible is already wired up. It does look like your PHY series drops the explicit requirement to set PHY_SUN4I_USB so that's better than what I was doing (adding a select directive under R528).

I can test your series if you want but I doubt it intersects my work here in any significant way.

Quoted 4 lines
Quoted 1 line

- Ethernet MAC+PHY support

Anything surprising here? Is that using an already supported external PHY?

The only surprise was this was how I noticed that CONFIG_CLK_SUN20I_D1 was not being implicitly enabled. Enabling that was then how I found that the clock driver wasn't compatible with current upstream (which I already mentioned).

The PHY is external and already supported, adding it to my DT required very little work.

Quoted 5 lines
Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

GPIO is completely OotB, yes. I²C is OotB once MVTWSI_CONTROL_CLEAR_IFLG is set correctly. (The pinctrl requirements for it are a little harder, more on that below.)

Quoted 2 lines
Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Quoted 8 lines
Quoted 2 lines

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?

Unsetting it is required for reset_cpu() to be defined. Your patchset updates that function (albeit without adding the WDT key, so the current patch is broken) to support NCAT2 already. U-Boot has no driver for "allwinner,sun20i-d1-wdt-reset", so this is the only way for reset to work.

So I had a look at this, and it's a bit surprising:
The watchdog driver already supports "allwinner,sun20i-d1-wdt" for a while. We don't need to list the "-reset" version, because the normal compatible name acts as a fallback string. However the DT node in the base .dtsi sets: status = "reserved"; for this (and the other) watchdog, so U-Boot's DM (correctly!) ignores those devices. Trying to figure out why. Adding:

Quoted 4 lines
&wdt {
        status = "okay";
};

to sun8i-t113s.dtsi fixes that for me, now the reset command works.

I did it the same way for myself. 🙂 But I thought this was the wrong way and the watchdog should be managed by a trusted OS or something like that. (which we don't have in the mainline yet)

#60 lore raw

On Fri, 16 Jun 2023 19:27:16 +0300
Maxim Kiselev <[email protected]> wrote:

Hi Maxim,

thanks for the reply! If you have anything that is missing or broken in the new version of the patchset I put on github, please let me know.

Quoted 130 lines

пт, 16 июн. 2023 г. в 18:59, Andre Przywara <[email protected]>:

Quoted 124 lines

On Mon, 12 Jun 2023 15:18:17 -0600
Sam Edwards <[email protected]> wrote:

Hi Sam,

something regarding "reset" below ...

Quoted 100 lines · Andre Przywara
Quoted 4 lines

Thanks for the update and the list! Can you confirm where you still needed code changes compared to say my github branch plus the changes we already discussed? Trying some guesses below, please confirm or deny:

Preeeeetttttyyy much everything I've changed locally has been submitted to the list or discussed in the relevant patchset. Have you updated your GitHub branch recently (past couple of weeks)? I haven't been watching it but I can pull it again and see which of my local changes are still required.

Quoted 5 lines
Quoted 2 lines

I have a build of U-Boot for my target, complete with:
- UART3 initialized correctly

this is problematic because of the other pinmux used on your board, which cannot easily be encoded alongside the existing UART3 pinmux?

Actually no, my board's UART3 is on PB6/PB7, nice and standard.

Quoted 4 lines
Quoted 2 lines

- DRAM coming up correctly
- SPL sets configured boot clock correctly

This should work as per github?

Yep, everything was working satisfactorily once I figured out I needed to set CONFIG_SYS_CLK_FREQ to get acceptable boot speeds.

Quoted 3 lines
Quoted 1 line

- SPI-NAND support (SPL and U-Boot proper)

This is with Icenow's series? Any D1 specific changes needed there?

Yes, with Icenowy's series (322733).

I learned that the BROM sets the boot medium code to 0x04 when it's an SPI-*NAND* (while older chips used 0x03 for "it's either SPI-NOR or SPI-NAND, good luck figuring out which"). Since env_get_location assumes BOOT_DEVICE_SPI is NOR (and my target needs to load env from UBI iff booting from NAND), I'm hoping I can convince Icenowy to separate out the SPI-NAND and SPI-NOR load methods entirely (vs. her current try-NAND-then-NOR approach) with the aid of some disambiguation logic to probe for an SPI-NAND on the older chips known to report these as 0x03.

I also needed Maksim's patch series (355747) to support the D1 SPI master.

Quoted 4 lines
Quoted 2 lines

- MMC support (SPL and U-Boot proper)
- SPL boot from FEL

again worked already in github?

Yes and yes. I was just confirming they're good; no local work needed from me here.

Quoted 6 lines
Quoted 1 line

- USB gadget support

So with the fixed SUNXI_SRAMC_BASE you said it worked? What about the USB PHY? That needs at least wiring in the compatible string? If you have such a patch, can you please rebase it on top of my v2 USB PHY series and post that?

Yes, with corrected SUNXI_SRAMC_BASE -- though I also needed my patches to make musb-new/sunxi.c use the UDC gadget model in DM (series 358842), as I don't think there's another way to init the controller at runtime.

I can't say whether the endpoint limit is correct or that mUSB *host* operation works.

The USB PHY only required that CONFIG_PHY_SUN4I_USB be enabled. The correct compatible is already wired up. It does look like your PHY series drops the explicit requirement to set PHY_SUN4I_USB so that's better than what I was doing (adding a select directive under R528).

I can test your series if you want but I doubt it intersects my work here in any significant way.

Quoted 4 lines
Quoted 1 line

- Ethernet MAC+PHY support

Anything surprising here? Is that using an already supported external PHY?

The only surprise was this was how I noticed that CONFIG_CLK_SUN20I_D1 was not being implicitly enabled. Enabling that was then how I found that the clock driver wasn't compatible with current upstream (which I already mentioned).

The PHY is external and already supported, adding it to my DT required very little work.

Quoted 5 lines
Quoted 2 lines

- I²C support *
- GPIO support (LEDs, buttons, misc. board management)

again should work out of the box, minus your board specific configuration?

GPIO is completely OotB, yes. I²C is OotB once MVTWSI_CONTROL_CLEAR_IFLG is set correctly. (The pinctrl requirements for it are a little harder, more on that below.)

Quoted 2 lines
Quoted 1 line

- reset working (requries CONFIG_SYSRESET unset, WDT key)

Quoted 8 lines
Quoted 2 lines

Isn't "CONFIG_SYSRESET unset" a hack? I dimly remember we had this for some other SoC initially, but later got rid of it?

Unsetting it is required for reset_cpu() to be defined. Your patchset updates that function (albeit without adding the WDT key, so the current patch is broken) to support NCAT2 already. U-Boot has no driver for "allwinner,sun20i-d1-wdt-reset", so this is the only way for reset to work.

So I had a look at this, and it's a bit surprising:
The watchdog driver already supports "allwinner,sun20i-d1-wdt" for a while. We don't need to list the "-reset" version, because the normal compatible name acts as a fallback string. However the DT node in the base .dtsi sets: status = "reserved"; for this (and the other) watchdog, so U-Boot's DM (correctly!) ignores those devices. Trying to figure out why. Adding:

Quoted 4 lines
&wdt {
        status = "okay";
};

to sun8i-t113s.dtsi fixes that for me, now the reset command works.

Quoted 3 lines

I did it the same way for myself. 🙂 But I thought this was the wrong way and the watchdog should be managed by a trusted OS or something like that. (which we don't have in the mainline yet)

Well, the name "reserved" suggests so, but I think it's really that those watchdogs don't seem to affect the RISC-V core, that's why there is a separate one (riscv_wdt). To avoid those watchdogs being picked up the any (RISC-V) OS, they are marked as reserved in the *shared* .dtsi. So I think marking the one as "okay" in the ARM specific .dtsi is the way to go, but I will wait for someone confirming the reason behind it.

Cheers,
Andre

#61 lore raw

Hi Andre,

пт, 16 июн. 2023 г. в 19:36, Andre Przywara <[email protected]>:
[..]

Quoted 3 lines

thanks for the reply! If you have anything that is missing or broken in the new version of the patchset I put on github, please let me know.

I tried the new version and everything looks pretty good for me. Great job! Just one note. Could you please add SUNXI_R_CPUCFG_BASE 0x07000400 to cpu_sunxi_ncat2.h file. This register is required for Sam's PCSI patches. Otherwise it leads to undeclared error:
In file included from ./arch/arm/include/asm/armv7.h:60,
from arch/arm/cpu/armv7/sunxi/psci.c:16:
arch/arm/cpu/armv7/sunxi/psci.c: In function ‘sunxi_cpu_set_entry’:
arch/arm/cpu/armv7/sunxi/psci.c:138:24: error:
‘SUNXI_R_CPUCFG_BASE’ undeclared (first use in this function); did you mean ‘SUNXI_CPUCFG_BASE’?

      138 |                        SUNXI_R_CPUCFG_BASE + SUN8I_R528_SOFT_ENTRY);
            |                        ^~~~~~~~~~~~~~~~~~~