Skip to contentSkip to conversation

ARM: clps711x: Switch to devicetree usage

PATCH Superseded Alexander Shiyan 3 participants 4 messages May 20, 2022

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: clps711x: Switch to devicetree usage

This is a complex patch that switches the ARM CLPS711X architecture to work with the device tree. Includes changes to board initialization and any architecture drivers used.

---
 arch/arm/Kconfig                              |   4 +
 arch/arm/boards/clep7212/Makefile             |   4 +-
 arch/arm/boards/clep7212/board.c              |  38 ++++++
 arch/arm/boards/clep7212/clep7212.c           |  57 --------
 arch/arm/boards/clep7212/lowlevel.c           |  24 ++--
 arch/arm/configs/clps711x_defconfig           |   5 +-
 arch/arm/dts/Makefile                         |   1 +
 arch/arm/dts/ep7212-clep7212.dts              |  64 +++++++++
 arch/arm/mach-clps711x/Kconfig                |   9 --
 arch/arm/mach-clps711x/Makefile               |   2 +-
 arch/arm/mach-clps711x/clock.c                |  46 +++----
 arch/arm/mach-clps711x/common.c               | 129 ++++++++++++++++++
 .../arm/mach-clps711x/include/mach/clps711x.h |  28 ++--
 .../arm/mach-clps711x/include/mach/debug_ll.h |  21 +++
 arch/arm/mach-clps711x/include/mach/devices.h |   9 --
 arch/arm/mach-clps711x/lowlevel.c             |  72 +++++-----
 arch/arm/mach-clps711x/reset.c                |  29 ----
 drivers/clocksource/clps711x.c                |   5 +
 drivers/gpio/gpio-clps711x.c                  |   5 +-
 drivers/serial/serial_clps711x.c              |  55 ++++----
 images/Makefile                               |   1 +
 images/Makefile.clps711x                      |   8 ++
 22 files changed, 396 insertions(+), 220 deletions(-)
 create mode 100644 arch/arm/boards/clep7212/board.c
 delete mode 100644 arch/arm/boards/clep7212/clep7212.c
 create mode 100644 arch/arm/dts/ep7212-clep7212.dts
 create mode 100644 arch/arm/mach-clps711x/common.c
 create mode 100644 arch/arm/mach-clps711x/include/mach/debug_ll.h
 delete mode 100644 arch/arm/mach-clps711x/include/mach/devices.h
 delete mode 100644 arch/arm/mach-clps711x/reset.c
 create mode 100644 images/Makefile.clps711x
arch/arm/Kconfig +4 -0
index 299e0ab080..8a1d75c19b 100644
@@ -66,9 +66,13 @@ config ARCH_CLPS711X
 	select CLKDEV_LOOKUP
 	select CLOCKSOURCE_CLPS711X
 	select COMMON_CLK
+	select COMMON_CLK_OF_PROVIDER
 	select CPU_32v4T
 	select GPIOLIB
+	select HAS_DEBUG_LL
+	select HAVE_PBL_MULTI_IMAGES
 	select MFD_SYSCON
+	select RELOCATABLE
 
 config ARCH_DAVINCI
 	bool "TI Davinci"
arch/arm/boards/clep7212/Makefile +2 -2
index 096120e567..85d92c8a7f 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-obj-y += clep7212.o
+obj-y += board.o
 lwl-y += lowlevel.o
-bbenv-y += defaultenv-clep7212
+bbenv-$(CONFIG_DEFAULT_ENVIRONMENT) += defaultenv-clep7212
arch/arm/boards/clep7212/board.c new file +38 -0
new file mode 100644
index 0000000000..9603facc10
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: Alexander Shiyan <[email protected]>
+
+#include <envfs.h>
+#include <init.h>
+#include <of.h>
+#include <stdio.h>
+#include <asm/io.h>
+#include <mach/clps711x.h>
+
+static int clep7212_dt_fixup(struct device_node *root, void *context)
+{
+	char *serial = basprintf("%08x%08x", 0, readl(UNIQID));
+
+	of_set_property(root, "serial-number", serial, strlen(serial) + 1, 1);
+
+	free(serial);
+
+	return 0;
+}
+
+static __init int clep7212_fixup(void)
+{
+	if (of_machine_is_compatible("cirrus,ep7209"))
+		of_register_fixup(clep7212_dt_fixup, NULL);
+
+	return 0;
+}
+postcore_initcall(clep7212_fixup);
+
+static __init int clep7212_defaultenv_init(void)
+{
+	if (of_machine_is_compatible("cirrus,ep7209"))
+		defaultenv_append_directory(defaultenv_clep7212);
+
+	return 0;
+}
+device_initcall(clep7212_defaultenv_init);
arch/arm/boards/clep7212/clep7212.c deleted +0 -57

57 lines not on this page · raw message

arch/arm/boards/clep7212/lowlevel.c +12 -12
index 41827dfa16..845e893d98 100644
@@ -1,22 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
-// SPDX-FileCopyrightText: 2012 Alexander Shiyan <[email protected]>
+// SPDX-FileCopyrightText: Alexander Shiyan <[email protected]>
 
+#include <asm/barebox-arm.h>
 #include <common.h>
-#include <init.h>
-
-#include <asm/barebox-arm-head.h>
-
 #include <mach/clps711x.h>
 
-#ifdef CONFIG_CLPS711X_RAISE_CPUFREQ
-# define CLPS711X_CPU_PLL_MULT	50
-#else
-# define CLPS711X_CPU_PLL_MULT	40
-#endif
+extern char __dtb_ep7212_clep7212_start[];
 
-void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
+ENTRY_FUNCTION(start_ep7212_clep7212, r0, r1, r2)
 {
+	void *fdt;
+
 	arm_cpu_lowlevel_init();
 
-	clps711x_barebox_entry(CLPS711X_CPU_PLL_MULT, NULL);
+	/* Stack in SRAM */
+	arm_setup_stack(CS6_BASE - 16);
+
+	fdt = __dtb_ep7212_clep7212_start;
+
+	clps711x_start(fdt + get_runtime_offset());
 }
arch/arm/configs/clps711x_defconfig +4 -1
index d9eab565b9..684ae79e22 100644
@@ -1,8 +1,8 @@
 CONFIG_ARCH_CLPS711X=y
+CONFIG_CLPS711X_RAISE_CPUFREQ=y
 CONFIG_AEABI=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 # CONFIG_MEMINFO is not set
-CONFIG_PBL_IMAGE=y
 CONFIG_MMU=y
 CONFIG_EXPERIMENTAL=y
 CONFIG_BAUDRATE=57600
@@ -28,6 +28,8 @@ CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_CRC=y
 CONFIG_CMD_CRC_CMP=y
 CONFIG_CMD_FLASH=y
+CONFIG_OFDEVICE=y
+CONFIG_OF_BAREBOX_DRIVERS=y
 # CONFIG_SPI is not set
 CONFIG_MTD=y
 CONFIG_DRIVER_CFI=y
@@ -36,6 +38,7 @@ CONFIG_DRIVER_CFI=y
 CONFIG_DISK=y
 CONFIG_DISK_WRITE=y
 CONFIG_DISK_INTF_PLATFORM_IDE=y
+# CONFIG_PINCTRL is not set
 CONFIG_FS_CRAMFS=y
 CONFIG_FS_FAT=y
 CONFIG_FS_FAT_LFN=y
arch/arm/dts/Makefile +1 -0
index e0177d84e4..f6edc46052 100644
@@ -8,6 +8,7 @@ lwl-$(CONFIG_MACH_ADVANTECH_ROM_742X) += imx6dl-advantech-rom-7421.dtb.o
 lwl-$(CONFIG_MACH_AFI_GF) += am335x-afi-gf.dtb.o
 lwl-$(CONFIG_MACH_BEAGLEBONE) += am335x-bone.dtb.o am335x-boneblack.dtb.o am335x-bone-common.dtb.o
 lwl-$(CONFIG_MACH_CANON_A1100) += canon-a1100.dtb.o
+lwl-$(CONFIG_MACH_CLEP7212) += ep7212-clep7212.dtb.o
 lwl-$(CONFIG_MACH_CM_FX6) += imx6dl-cm-fx6.dtb.o imx6q-cm-fx6.dtb.o imx6q-utilite.dtb.o
 lwl-$(CONFIG_MACH_DFI_FS700_M60) += imx6q-dfi-fs700-m60-6q.dtb.o imx6dl-dfi-fs700-m60-6s.dtb.o
 lwl-$(CONFIG_MACH_DUCKBILL) += imx28-duckbill.dtb.o
arch/arm/dts/ep7212-clep7212.dts new file +64 -0

64 lines not on this page · raw message

arch/arm/mach-clps711x/Kconfig +0 -9
index 52cf8468c0..6cf6bc37a2 100644
@@ -16,7 +16,6 @@ menu "CLPS711X specific settings"
 
 config CLPS711X_RAISE_CPUFREQ
 	bool "Raise CPU frequency to 90 MHz"
-	depends on MACH_CLEP7212
 	help
 	  Raise CPU frequency to 90 MHz. This operation can be performed
 	  only for devices which allow to operate at 90 MHz.
@@ -24,12 +23,4 @@ config CLPS711X_RAISE_CPUFREQ
 
 endmenu
 
-config ARCH_TEXT_BASE
-	hex
-	default 0xc0740000 if MACH_CLEP7212
-
-config BAREBOX_MAX_IMAGE_SIZE
-	hex
-	default 0x00080000 if MACH_CLEP7212
-
 endif
arch/arm/mach-clps711x/Makefile +1 -1
index 4d5950d9b5..871c5f7e9c 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-obj-y += clock.o devices.o reset.o
+obj-y += clock.o common.o
 lwl-y += lowlevel.o
arch/arm/mach-clps711x/clock.c +22 -24

76 lines not on this page · raw message

arch/arm/mach-clps711x/common.c new file +129 -0

129 lines not on this page · raw message

arch/arm/mach-clps711x/include/mach/clps711x.h +18 -10
index 957b2b8477..9aef7f3fd3 100644
@@ -1,13 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
- *  Hardware definitions for Cirrus Logic CLPS711X
- *
- *  Copyright (C) 2000 Deep Blue Solutions Ltd.
- *  Copyright (C) 2012 Alexander Shiyan <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2000 Deep Blue Solutions Ltd.
+ * Copyright (C) 2012-2022 Alexander Shiyan <[email protected]>
  */
 
 #ifndef __MACH_CLPS711X_H
@@ -159,6 +153,10 @@
 #define SYSCON2_CLKENSL		(1 << 13)
 #define SYSCON2_BUZFREQ		(1 << 14)
 
+#define SYSCON_UARTEN		(1 << 8)
+#define SYSFLG_UBUSY		(1 << 11)
+#define SYSFLG_UTXFF		(1 << 23)
+
 #define SYNCIO_FRMLEN(x)	(((x) & 0x1f) << 8)
 #define SYNCIO_SMCKEN		(1 << 13)
 #define SYNCIO_TXFRMEN		(1 << 14)
@@ -247,6 +245,16 @@
 #define MEMCFG_WAITSTATE_2_0	(14 << 2)
 #define MEMCFG_WAITSTATE_1_0	(15 << 2)
 
-void clps711x_barebox_entry(u32, void *);
+#define UBRLCR_BREAK		(1 << 12)
+#define UBRLCR_PRTEN		(1 << 13)
+#define UBRLCR_EVENPRT		(1 << 14)
+#define UBRLCR_XSTOP		(1 << 15)
+#define UBRLCR_FIFOEN		(1 << 16)
+#define UBRLCR_WRDLEN5		(0 << 17)
+#define UBRLCR_WRDLEN6		(1 << 17)
+#define UBRLCR_WRDLEN7		(2 << 17)
+#define UBRLCR_WRDLEN8		(3 << 17)
+
+void clps711x_start(void *);
 
 #endif
arch/arm/mach-clps711x/include/mach/debug_ll.h new file +21 -0
new file mode 100644
index 0000000000..342bb7628a
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: Alexander Shiyan <[email protected]>
+
+#ifndef __MACH_DEBUG_LL_H__
+#define __MACH_DEBUG_LL_H__
+
+#include <asm/io.h>
+#include <mach/clps711x.h>
+
+static inline void PUTC_LL(char c)
+{
+	do {
+	} while (readl(SYSFLG1) & SYSFLG_UTXFF);
+
+	writew(c, UARTDR1);
+
+	do {
+	} while (readl(SYSFLG1) & SYSFLG_UBUSY);
+}
+
+#endif
arch/arm/mach-clps711x/include/mach/devices.h deleted +0 -9
deleted file mode 100644
index 77c43be25c..0000000000
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __MACH_DEVICES_H
-#define __MACH_DEVICES_H
-
-void clps711x_setup_memcfg(int bank, u32 val);
-void clps711x_add_uart(unsigned int id);
-
-#endif
arch/arm/mach-clps711x/lowlevel.c +38 -34

105 lines not on this page · raw message

arch/arm/mach-clps711x/reset.c deleted +0 -29
deleted file mode 100644
index 90ddb8f5d2..0000000000
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2012 Alexander Shiyan <[email protected]>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
-
-#include <common.h>
-#include <init.h>
-#include <restart.h>
-
-static void __noreturn clps711x_restart_soc(struct restart_handler *rst)
-{
-	shutdown_barebox();
-
-	asm("mov pc, #0");
-
-	hang();
-}
-
-static int restart_register_feature(void)
-{
-	restart_handler_register_fn("vector", clps711x_restart_soc);
-
-	return 0;
-}
-coredevice_initcall(restart_register_feature);
drivers/clocksource/clps711x.c +5 -0
index 1fe7f6c891..8465ee502f 100644
@@ -27,6 +27,11 @@ static int clps711x_cs_probe(struct device_d *dev)
 	struct resource *iores;
 	u32 rate;
 	struct clk *timer_clk;
+	int id;
+
+	id = of_alias_get_id(dev->device_node, "timer");
+	if (id != 1)
+		return 0;
 
 	timer_clk = clk_get(dev, NULL);
 	if (IS_ERR(timer_clk))
drivers/gpio/gpio-clps711x.c +1 -4
index a1965b33e4..45035e7a09 100644
@@ -10,13 +10,10 @@
 static int clps711x_gpio_probe(struct device_d *dev)
 {
 	struct resource *iores;
-	int err, id = dev->id;
+	int err, id = of_alias_get_id(dev->device_node, "gpio");
 	void __iomem *dat, *dir = NULL, *dir_inv = NULL;
 	struct bgpio_chip *bgc;
 
-	if (dev->device_node)
-		id = of_alias_get_id(dev->device_node, "gpio");
-
 	if (id < 0 || id > 4)
 		return -ENODEV;
 
drivers/serial/serial_clps711x.c +27 -28

120 lines not on this page · raw message

images/Makefile +1 -0
index 5e2b9ecaaa..a148cf4176 100644
@@ -152,6 +152,7 @@ include $(srctree)/images/Makefile.ar231x
 include $(srctree)/images/Makefile.ath79
 include $(srctree)/images/Makefile.bcm283x
 include $(srctree)/images/Makefile.bcm47xx
+include $(srctree)/images/Makefile.clps711x
 include $(srctree)/images/Makefile.imx
 include $(srctree)/images/Makefile.loongson
 include $(srctree)/images/Makefile.malta
images/Makefile.clps711x new file +8 -0
new file mode 100644
index 0000000000..d76911d627
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# barebox image generation Makefile for CLPS711X images
+#
+
+pblb-$(CONFIG_MACH_CLEP7212) += start_ep7212_clep7212
+FILE_barebox-ep7212-clep7212.img = start_ep7212_clep7212.pblb
+image-$(CONFIG_MACH_CLEP7212) += barebox-ep7212-clep7212.img
Signature · 7 lines
2.32.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hello,

Quoted 10 lines · Alexander Shiyan

This is a complex patch that switches the ARM CLPS711X architecture to work with the device tree. Includes changes to board initialization and any architecture drivers used.

arch/arm/boards/clep7212/Makefile +0 -0
index 096120e567..85d92c8a7f 100644

arch/arm/boards/clep7212/Makefile

Quoted 9 lines
arch/arm/boards/clep7212/Makefile +8 -0
 
+static __init int clep7212_fixup(void)
+{
+	if (of_machine_is_compatible("cirrus,ep7209"))
+		of_register_fixup(clep7212_dt_fixup, NULL);
+
+	return 0;
+}
+postcore_initcall(clep7212_fixup);

You can replace this with the new barebox_set_serial_number(), see:
https://git.pengutronix.de/cgit/barebox/commit/?h=next&id=f6756e9ce6f26dc22506e25bd5cf1a4f6a173636

arch/arm/boards/clep7212/Makefile

Quoted 10 lines
arch/arm/boards/clep7212/Makefile +5 -2
-void __naked __bare_init barebox_arm_reset_vector(uint32_t r0, uint32_t r1, uint32_t r2)
+ENTRY_FUNCTION(start_ep7212_clep7212, r0, r1, r2)
 {
+	void *fdt;
+
 	arm_cpu_lowlevel_init();
 
-	clps711x_barebox_entry(CLPS711X_CPU_PLL_MULT, NULL);
+	/* Stack in SRAM */
+	arm_setup_stack(CS6_BASE - 16);

please use ENTRY_FUNCTION_WITHSTACK instead to be a bit more future-proof. Also - 16 is not necessary, see 6b3dc4abd884 ("ARM: Cleanup stack offset cargo cult").

arch/arm/mach-clps711x/common.c line 43

Quoted 9 lines
arch/arm/mach-clps711x/common.c new file +3 -0
new file mode 100644
index 0000000000..d9f702a9b1
 
+static void clps711x_bus_patch(struct device_node *node,
+			       u32 compare, u32 change)
+{

Could you add a comment why this is necessary?

Cheers,
Ahmad

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

Hello.

пт, 20 мая 2022 г. в 12:56, Ahmad Fatoum <[email protected]>:

Quoted 7 lines

Hello,

Quoted 3 lines · Alexander Shiyan

This is a complex patch that switches the ARM CLPS711X architecture to work with the device tree. Includes changes to board initialization and any architecture drivers used.

...

Quoted 11 lines

arch/arm/boards/clep7212/board.c line 29

Quoted 8 lines
arch/arm/boards/clep7212/board.c new file +8 -0
+static __init int clep7212_fixup(void)
+{
+     if (of_machine_is_compatible("cirrus,ep7209"))
+             of_register_fixup(clep7212_dt_fixup, NULL);
+
+     return 0;
+}
+postcore_initcall(clep7212_fixup);

You can replace this with the new barebox_set_serial_number(), see:
https://git.pengutronix.de/cgit/barebox/commit/?h=next&id=f6756e9ce6f26dc22506e25bd5cf1a4f6a173636

This change is currently in the next branch, but Ok.

Quoted 6 lines
Quoted 6 lines
arch/arm/boards/clep7212/lowlevel.c +3 -0
+ENTRY_FUNCTION(start_ep7212_clep7212, r0, r1, r2)
 {
+     void *fdt;
+
      arm_cpu_lowlevel_init();
Quoted 7 lines

arch/arm/boards/clep7212/lowlevel.c line 17

Quoted 3 lines
arch/arm/boards/clep7212/lowlevel.c +2 -1
-     clps711x_barebox_entry(CLPS711X_CPU_PLL_MULT, NULL);
+     /* Stack in SRAM */
+     arm_setup_stack(CS6_BASE - 16);

please use ENTRY_FUNCTION_WITHSTACK instead to be a bit more future-proof. Also - 16 is not necessary, see 6b3dc4abd884 ("ARM: Cleanup stack offset cargo cult").

Ok.

Quoted 5 lines

arch/arm/mach-clps711x/common.c line 43

Quoted 3 lines
arch/arm/mach-clps711x/common.c new file +3 -0
+static void clps711x_bus_patch(struct device_node *node,
+                            u32 compare, u32 change)
+{

Could you add a comment why this is necessary?

Because the barebox cannot use address 0 (NOR MTD in my case), the bus driver scans for devices that start at zero address and maps them to a different unused address.
To start the kernel, a fixup is used that rewrites the address of the patched device to its original state.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 23 lines · Alexander Shiyan

Hello.

пт, 20 мая 2022 г. в 12:56, Ahmad Fatoum <[email protected]>:

Quoted 7 lines

Hello,

Quoted 3 lines · Alexander Shiyan

This is a complex patch that switches the ARM CLPS711X architecture to work with the device tree. Includes changes to board initialization and any architecture drivers used.

...

Quoted 11 lines

arch/arm/boards/clep7212/board.c line 29

Quoted 8 lines
arch/arm/boards/clep7212/board.c new file +8 -0
+static __init int clep7212_fixup(void)
+{
+     if (of_machine_is_compatible("cirrus,ep7209"))
+             of_register_fixup(clep7212_dt_fixup, NULL);
+
+     return 0;
+}
+postcore_initcall(clep7212_fixup);

You can replace this with the new barebox_set_serial_number(), see:
https://git.pengutronix.de/cgit/barebox/commit/?h=next&id=f6756e9ce6f26dc22506e25bd5cf1a4f6a173636

Quoted 1 line

This change is currently in the next branch, but Ok.

It's in master now.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox