[PATCH v2 2/3] net: dhcp6: pxe: Add DHCP/PXE commands for IPv6

2023-04-06 Thread seanedmond
From: Sean Edmond 

Adds commands to support DHCP and PXE with IPv6.

New configs added:
- CMD_DHCP6
- DHCP6_PXE_CLIENTARCH
- DHCP6_PXE_DHCP_OPTION
- DHCP6_ENTERPRISE_ID

New commands added (when IPv6 is enabled):
- dhcp6
- pxe get -ipv6
- pxe boot -ipv6

Signed-off-by: Sean Edmond 
---
 boot/bootmeth_distro.c |  2 +-
 boot/bootmeth_pxe.c|  4 +-
 boot/pxe_utils.c   |  3 +-
 cmd/Kconfig| 26 +
 cmd/net.c  | 23 +++
 cmd/pxe.c  | 86 +-
 cmd/sysboot.c  |  2 +-
 include/pxe_utils.h| 10 -
 8 files changed, 140 insertions(+), 16 deletions(-)

diff --git a/boot/bootmeth_distro.c b/boot/bootmeth_distro.c
index 356929828b..b4b73ecbf5 100644
--- a/boot/bootmeth_distro.c
+++ b/boot/bootmeth_distro.c
@@ -150,7 +150,7 @@ static int distro_boot(struct udevice *dev, struct bootflow 
*bflow)
info.dev = dev;
info.bflow = bflow;
ret = pxe_setup_ctx(&ctx, &cmdtp, distro_getfile, &info, true,
-   bflow->subdir);
+   bflow->subdir, false);
if (ret)
return log_msg_ret("ctx", -EINVAL);
 
diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c
index ecf8557af8..5a8af2bbd0 100644
--- a/boot/bootmeth_pxe.c
+++ b/boot/bootmeth_pxe.c
@@ -70,7 +70,7 @@ static int distro_pxe_read_bootflow(struct udevice *dev, 
struct bootflow *bflow)
addr = simple_strtoul(addr_str, NULL, 16);
 
log_debug("calling pxe_get()\n");
-   ret = pxe_get(addr, &bootdir, &size);
+   ret = pxe_get(addr, &bootdir, &size, false);
log_debug("pxe_get() returned %d\n", ret);
if (ret)
return log_msg_ret("pxeb", ret);
@@ -146,7 +146,7 @@ static int distro_pxe_boot(struct udevice *dev, struct 
bootflow *bflow)
info.bflow = bflow;
info.cmdtp = &cmdtp;
ret = pxe_setup_ctx(ctx, &cmdtp, distro_pxe_getfile, &info, false,
-   bflow->subdir);
+   bflow->subdir, false);
if (ret)
return log_msg_ret("ctx", -EINVAL);
 
diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 3a1e50f2b1..d13c47dd94 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -1578,7 +1578,7 @@ void handle_pxe_menu(struct pxe_context *ctx, struct 
pxe_menu *cfg)
 
 int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
  pxe_getfile_func getfile, void *userdata,
- bool allow_abs_path, const char *bootfile)
+ bool allow_abs_path, const char *bootfile, bool use_ipv6)
 {
const char *last_slash;
size_t path_len = 0;
@@ -1588,6 +1588,7 @@ int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl 
*cmdtp,
ctx->getfile = getfile;
ctx->userdata = userdata;
ctx->allow_abs_path = allow_abs_path;
+   ctx->use_ipv6 = use_ipv6;
 
/* figure out the boot directory, if there is one */
if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index bab35fc667..8448cf3400 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1672,6 +1672,15 @@ config CMD_DHCP
help
  Boot image via network using DHCP/TFTP protocol
 
+config CMD_DHCP6
+   bool "dhcp6"
+   depends on IPV6
+   help
+ Boot image via network using DHCPv6/TFTP protocol using IPv6.
+
+ Will perform 4-message exchange with DHCPv6 server, requesting
+ the minimum required options to TFTP boot. Complies with RFC 8415.
+
 config BOOTP_MAY_FAIL
bool "Allow for the BOOTP/DHCP server to not be found"
depends on CMD_BOOTP
@@ -1785,6 +1794,23 @@ config BOOTP_VCI_STRING
default "U-Boot.arm" if ARM
default "U-Boot"
 
+if CMD_DHCP6
+
+config DHCP6_PXE_CLIENTARCH
+   hex
+   default 0x16 if ARM64
+   default 0x15 if ARM
+   default 0xFF
+
+config DHCP6_PXE_DHCP_OPTION
+   bool "Request & store 'pxe_configfile' from DHCP6 server"
+
+config DHCP6_ENTERPRISE_ID
+   int "Enterprise ID to send in DHCPv6 Vendor Class Option"
+   default 0
+
+endif
+
 config CMD_TFTPBOOT
bool "tftpboot"
default y
diff --git a/cmd/net.c b/cmd/net.c
index d5e20843dd..95529a9d12 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -111,6 +111,29 @@ U_BOOT_CMD(
 );
 #endif
 
+#if defined(CONFIG_CMD_DHCP6)
+static int do_dhcp6(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   int i;
+   int dhcp_argc;
+   char *dhcp_argv[] = {NULL, NULL, NULL, NULL};
+
+   /* Add -ipv6 flag for autoload */
+   for (i = 0; i < argc; i++)
+   dhcp_argv[i] = argv[i];
+   dhcp_argc = argc + 1;
+   dhcp_argv[dhcp_argc - 1] =  USE_IP6_CMD_PARAM;
+
+   return netboot_common(DHCP6, cmdtp, dhcp_argc, dhcp_argv);
+}
+
+U_BOOT_CMD(dhcp6,  3,  1,  do_dhcp6,
+  "boot image via network using DHCPv6/TFTP protocol. \n"

[PATCH v2 1/3] net: dhcp6: Add DHCPv6 (DHCP for IPv6)

2023-04-06 Thread seanedmond
From: Sean Edmond 

Adds DHCPv6 protocol to u-boot.

Allows for address assignement with DHCPv6 4-message exchange
(SOLICIT->ADVERTISE->REQUEST->REPLY).  Includes DHCPv6 options
required by RFC 8415.  Also adds DHCPv6 options required
for PXE boot.

Possible enhancements:
- Duplicate address detection on DHCPv6 assigned address
- IPv6 address assignement through SLAAC
- Sending/parsing other DHCPv6 options (NTP, DNS, etc...)

Signed-off-by: Sean Edmond 
---
 include/net.h |   8 +-
 net/Makefile  |   1 +
 net/dhcpv6.c  | 735 ++
 net/dhcpv6.h  | 212 +++
 net/net.c |  12 +
 5 files changed, 966 insertions(+), 2 deletions(-)
 create mode 100644 net/dhcpv6.c
 create mode 100644 net/dhcpv6.h

diff --git a/include/net.h b/include/net.h
index 399af5e064..cac818e292 100644
--- a/include/net.h
+++ b/include/net.h
@@ -484,6 +484,10 @@ extern charnet_hostname[32];   /* Our hostname 
*/
 #ifdef CONFIG_NET
 extern charnet_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN];  /* Our root 
path */
 #endif
+#if defined(CONFIG_DHCP6_PXE_DHCP_OPTION)
+/* Indicates whether the pxe path prefix / config file was specified in dhcp 
option */
+extern char *pxelinux_configfile;
+#endif
 /** END OF BOOTP EXTENTIONS **/
 extern u8  net_ethaddr[ARP_HLEN];  /* Our ethernet address 
*/
 extern u8  net_server_ethaddr[ARP_HLEN];   /* Boot server enet 
address */
@@ -504,8 +508,8 @@ extern ushort   net_native_vlan;/* Our 
Native VLAN */
 extern int net_restart_wrap;   /* Tried all network devices */
 
 enum proto_t {
-   BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
-   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI, WGET
+   BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS, NFS, CDP,
+   NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI, 
WGET
 };
 
 extern charnet_boot_file_name[1024];/* Boot File name */
diff --git a/net/Makefile b/net/Makefile
index bea000b206..5968110170 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_IPV6) += net6.o
 obj-$(CONFIG_CMD_NFS)  += nfs.o
 obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_PING6) += ping6.o
+obj-$(CONFIG_CMD_DHCP6) += dhcpv6.o
 obj-$(CONFIG_CMD_PCAP) += pcap.o
 obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
diff --git a/net/dhcpv6.c b/net/dhcpv6.c
new file mode 100644
index 00..9204909c1f
--- /dev/null
+++ b/net/dhcpv6.c
@@ -0,0 +1,735 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) Microsoft Corporation
+ * Author: Sean Edmond 
+ *
+ */
+
+/* Simple DHCP6 network layer implementation. */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "dhcpv6.h"
+#include 
+#include 
+#include "net_rand.h"
+
+#define PORT_DHCP6_S   547 /* DHCP6 server UDP port */
+#define PORT_DHCP6_C   546 /* DHCP6 client UDP port */
+
+/* default timeout parameters (in ms) */
+#define SOL_MAX_DELAY_MS   1000
+#define SOL_TIMEOUT_MS 1000
+#define SOL_MAX_RT_MS  360
+#define REQ_TIMEOUT_MS 1000
+#define REQ_MAX_RT_MS  3
+#define REQ_MAX_RC 10
+#define MAX_WAIT_TIME_MS   6
+
+/* global variable to track any updates from DHCP6 server */
+int updated_sol_max_rt_ms = SOL_MAX_RT_MS;
+
+static void dhcp6_timeout_handler(void);
+static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len);
+static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len);
+
+struct dhcp6_sm_params sm_params;
+
+/*
+ * Handle DHCP received packets (set as UDP handler)
+ */
+static void dhcp6_handler(uchar *pkt, unsigned int dest, struct in_addr sip,
+ unsigned int src, unsigned int len)
+{
+   /* return if ports don't match DHCPv6 ports */
+   if (dest != PORT_DHCP6_C || src != PORT_DHCP6_S)
+   return;
+
+   dhcp6_state_machine(false, pkt, len);
+}
+
+/**
+ * dhcp6_add_option() - Adds DHCP6 option to a packet
+ * @option_id: The option ID to add (See DHCP6_OPTION_* definitions)
+ * @pkt: A pointer to the current write location of the TX packet
+ *
+ * Return: The number of bytes written into "*pkt"
+ */
+static int dhcp6_add_option(int option_id, uchar *pkt)
+{
+   struct dhcp6_option_duid_ll *duid_opt;
+   struct dhcp6_option_elapsed_time *elapsed_time_opt;
+   struct dhcp6_option_ia_ta *ia_ta_opt;
+   struct dhcp6_option_ia_na *ia_na_opt;
+   struct dhcp6_option_oro *oro_opt;
+   struct dhcp6_option_client_arch *client_arch_opt;
+   struct dhcp6_option_vendor_class *vendor_class_opt;
+   int opt_len;
+   long elapsed_time;
+   size_t vci_strlen;
+   int num_oro = 0;
+   int num_client_arch = 0;
+   int num_vc_data = 0;
+   struct dhcp6_option_hdr *dhcp_option = (struct dhcp6_opt

[PATCH v2 0/3] *** net: DHCPv6 protocol and commands ***

2023-04-06 Thread seanedmond
From: Sean Edmond 

The recently integrated IPv6 patch series relies on the link-local address,
or a statically assigned IPv6 address for network operations.  This patch
series adds IPv6 address assignment through DHCPv6.

The implementation meets the requirements in RFC 8415 for "Client/Server
Exchanges Involving Four Messages":
https://www.rfc-editor.org/rfc/rfc8415

The implementation sends/receives the minimum required DHCPv6 options to 
network boot.

A new command (dhcp6) will execute the protocol.  In addition, IPv6
functionality has been extended to the existing pxe commands ("pxe get"
and "pxe boot").

changes in v2:
- Add sandbox test in test_net.py
- Add CONFIG_CMD_DHCP6 to sandbox_defconfig
- fix comment style (/**/ instead of //)
- move addition of Kconfig from 1st patch to 2nd patch
- Fix warning (warning: label ‘error_exit’ defined but not used") when 
  CONFIG_DHCP6_PXE_DHCP_OPTION not configured
- Fix dhcp6 command help
- Use net_set_timeout_handler(0, NULL) in dhcpv6.c
- Move USE_IP6_CMD_PARAM back to net6.h

Sean Edmond (3):
  net: dhcp6: Add DHCPv6 (DHCP for IPv6)
  net: dhcp6: pxe: Add DHCP/PXE commands for IPv6
  net: dhcp6: Add a sandbox test for dhcp6

 boot/bootmeth_distro.c|   2 +-
 boot/bootmeth_pxe.c   |   4 +-
 boot/pxe_utils.c  |   3 +-
 cmd/Kconfig   |  26 ++
 cmd/net.c |  23 ++
 cmd/pxe.c |  86 -
 cmd/sysboot.c |   2 +-
 configs/sandbox_defconfig |   1 +
 include/net.h |   8 +-
 include/pxe_utils.h   |  10 +-
 net/Makefile  |   1 +
 net/dhcpv6.c  | 735 ++
 net/dhcpv6.h  | 212 +++
 net/net.c |  12 +
 test/py/tests/test_net.py |  25 ++
 15 files changed, 1132 insertions(+), 18 deletions(-)
 create mode 100644 net/dhcpv6.c
 create mode 100644 net/dhcpv6.h

-- 
2.40.0



[PATCH v2 3/3] net: dhcp6: Add a sandbox test for dhcp6

2023-04-06 Thread seanedmond
From: Sean Edmond 

Requires proper environment with DHCP6 server provisioned.

Signed-off-by: Sean Edmond 
---
 configs/sandbox_defconfig |  1 +
 test/py/tests/test_net.py | 25 +
 2 files changed, 26 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 3a1f14c60f..f65965f864 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -340,3 +340,4 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_CMD_DHCP6=y
diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index 9ca6743afd..0447c0b2e0 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -29,6 +29,11 @@ env__net_uses_pci = True
 # set to False.
 env__net_dhcp_server = True
 
+# True if a DHCPv6 server is attached to the network, and should be tested.
+# If DHCPv6 testing is not possible or desired, this variable may be omitted or
+# set to False.
+env__net_dhcp6_server = True
+
 # A list of environment variables that should be set in order to configure a
 # static IP. If solely relying on DHCP, this variable may be omitted or set to
 # an empty list.
@@ -58,6 +63,7 @@ env__net_nfs_readable_file = {
 """
 
 net_set_up = False
+net6_set_up = False
 
 def test_net_pre_commands(u_boot_console):
 """Execute any commands required to enable network hardware.
@@ -93,6 +99,25 @@ def test_net_dhcp(u_boot_console):
 global net_set_up
 net_set_up = True
 
+@pytest.mark.buildconfigspec('cmd_dhcp6')
+def test_net_dhcp6(u_boot_console):
+"""Test the dhcp6 command.
+
+The boardenv_* file may be used to enable/disable this test; see the
+comment at the beginning of this file.
+"""
+
+test_dhcp6 = u_boot_console.config.env.get('env__net_dhcp6_server', False)
+if not test_dhcp6:
+pytest.skip('No DHCP6 server available')
+
+u_boot_console.run_command('setenv autoload no')
+output = u_boot_console.run_command('dhcp6')
+assert 'DHCP6 client bound to ' in output
+
+global net6_set_up
+net6_set_up = True
+
 @pytest.mark.buildconfigspec('net')
 def test_net_setup_static(u_boot_console):
 """Set up a static IP configuration.
-- 
2.40.0



Re: [PATCH 4/8] tools: prelink-riscv: Unmap the ELF image when done

2023-04-06 Thread Rick Chen
> From: Bin Meng 
> Sent: Thursday, March 30, 2023 12:20 PM
> To: u-boot@lists.denx.de
> Cc: Leo Yu-Chi Liang(梁育齊) ; Rick Jian-Zhi Chen(陳建志) 
> 
> Subject: [PATCH 4/8] tools: prelink-riscv: Unmap the ELF image when done
>
> The codes forget to call munmap() to unmap the ELF image that was mapped by 
> previous mmap().
>
> Signed-off-by: Bin Meng 
> ---
>
>  tools/prelink-riscv.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Rick Chen 


Re: [PATCH 3/8] tools: prelink-riscv: Cosmetic style fixes

2023-04-06 Thread Rick Chen
> From: U-Boot  On Behalf Of Bin Meng
> Sent: Thursday, March 30, 2023 12:20 PM
> To: u-boot@lists.denx.de
> Subject: [PATCH 3/8] tools: prelink-riscv: Cosmetic style fixes
>
> Some coding convention fixes.
>
> Signed-off-by: Bin Meng 
> ---
>
>  tools/prelink-riscv.inc | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Rick Chen 


Re: [PATCH 2/8] riscv: Optimize loading relocation type

2023-04-06 Thread Rick Chen
> From: Bin Meng 
> Sent: Thursday, March 30, 2023 12:20 PM
> To: u-boot@lists.denx.de
> Cc: Leo Yu-Chi Liang(梁育齊) ; Nikita Shubin 
> ; Rick Jian-Zhi Chen(陳建志) 
> Subject: [PATCH 2/8] riscv: Optimize loading relocation type
>
> 't5' already contains relocation type so don't bother reloading it.
>
> Signed-off-by: Bin Meng 
> ---
>
>  arch/riscv/cpu/start.S | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Rick Chen 


[PATCH] riscv: Enforce DWARF4 output

2023-04-06 Thread Bin Meng
Since commit 409e4b547872 ("Makefile: Enforce DWARF4 output") the
whole U-Boot build switched to enforce DWARF4 output, but RISC-V
is still on its own setting. Let's switch to use U-Boot's setting.

Signed-off-by: Bin Meng 
---

 arch/riscv/config.mk | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/riscv/config.mk b/arch/riscv/config.mk
index a8ed3faf28..f74c3f37e6 100644
--- a/arch/riscv/config.mk
+++ b/arch/riscv/config.mk
@@ -24,8 +24,7 @@ EFI_LDS   := elf_riscv64_efi.lds
 endif
 
 PLATFORM_CPPFLAGS  += -ffixed-gp -fpic
-PLATFORM_RELFLAGS  += -fno-common -gdwarf-2 -ffunction-sections \
-  -fdata-sections
+PLATFORM_RELFLAGS  += -fno-common -ffunction-sections -fdata-sections
 LDFLAGS_u-boot += --gc-sections -static -pie
 
 EFI_CRT0   := crt0_riscv_efi.o
-- 
2.25.1



Re: [PATCH 2/9] clang: Add $(CLANG_TARGET) to LDPPFLAGS

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:49, Tom Rini  wrote:
>
> When we invoke $(CPP) to make u-boot.lds we have LDPPFLAGS available to
> set other required flags here. As this file is for the target and not
> the host, we must ensure that CPP knows what the target architecture is.
> For this, pass in $(CLANG_TARGET).
>
> Signed-off-by: Tom Rini 
> ---
>  Makefile | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH 1/8] riscv: Optimize source end address calculation in start.S

2023-04-06 Thread Rick Chen
> From: Bin Meng 
> Sent: Thursday, March 30, 2023 12:20 PM
> To: u-boot@lists.denx.de
> Cc: Leo Yu-Chi Liang(梁育齊) ; Nikita Shubin 
> ; Rick Jian-Zhi Chen(陳建志) 
> Subject: [PATCH 1/8] riscv: Optimize source end address calculation in start.S
>
> The __bss_start is the source end address hence load its address directly 
> into register 't2' for optimization.
>
> Signed-off-by: Bin Meng 
> ---
>
>  arch/riscv/cpu/start.S | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Rick Chen 


Re: [PATCH 1/9] arm: Only support ARM64_CRC32 when using GCC

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:49, Tom Rini  wrote:
>
> Today, only gcc has __builtin_aarch64_crc32b (clang-16 does not, for
> example). Make this option depend on CC_IS_GCC.
>
> Signed-off-by: Tom Rini 
> ---
>  arch/arm/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH] bootflow: Rework do_bootflow_menu() slightly

2023-04-06 Thread Simon Glass
On Fri, 7 Apr 2023 at 02:03, Tom Rini  wrote:
>
> When building this with clang, we get a warning such as:
> cmd/bootflow.c:412:27: warning: variable 'bflow' is uninitialized when used 
> here [-Wuninitialized]
> printf("Selected: %s\n", bflow->os_name ? bflow->os_name : 
> bflow->name);
>  ^
>
> And a suggestion to just initialize bflow to NULL. This would however
> would be ensuring a bad dereference. Instead, looking at the function we
> rework things so that when CONFIG_EXPO is not enabled (and so, no UI) we
> error early and would never reach this point in the code.  Simplify the
> rest slightly as well while at this.
>
> Signed-off-by: Tom Rini 
> ---
> Cc: Simon Glass 
> ---
>  cmd/bootflow.c | 24 
>  1 file changed, 12 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] pytest: Use --lazy with umount

2023-04-06 Thread Simon Glass
Hi Tom,

On Thu, 6 Apr 2023 at 14:19, Tom Rini  wrote:
>
> Sometimes when doing tests on real hardware we sometimes run in to the
> case where some of these mounts haven't been fully flushed.  Using the
> --lazy option with umount will allow us to continue while letting the OS
> handle flushing the data out still.
>
> Signed-off-by: Tom Rini 
> ---
>  test/py/tests/test_ut.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass 

I wonder if these ever actually succeed later on, or do they remain
mounted forever?

Regards,
SImon


Re: [PATCH 3/9] clang: Don't look for libgcc

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:50, Tom Rini  wrote:
>
> In the case of using clang to build, and having not already enabled the
> private libgcc, do not look for it, as it will not be found nor
> required.
>
> Signed-off-by: Tom Rini 
> ---
>  Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 9/9] doc: clang: Update and correct support notes

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:51, Tom Rini  wrote:
>
> At this point, clang can be used on both 32bit and 64bit targets without
> issue.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/build/clang.rst | 16 
>  1 file changed, 4 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] qemu: dfu: Correct memset call in set_dfu_alt_info

2023-04-06 Thread Simon Glass
On Fri, 7 Apr 2023 at 01:58, Tom Rini  wrote:
>
> When building with clang, we see:
> board/emulation/common/qemu_dfu.c:51:24: warning: 'memset' call operates on 
> objects of type 'char' while the size is based on a different type 'char *' 
> [-Wsizeof-pointer-memaccess]
>
> As we're calling memset with the length set to the size of the pointer
> and not the size of the buffer. Correct this with a call of the size of
> the buffer itself.
>
> Signed-off-by: Tom Rini 
> ---
> Cc: Tuomas Tynkkynen 
> Cc: Sughosh Ganu 
> Cc: Simon Glass 
> ---
>  board/emulation/common/qemu_dfu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH 6/9] boot/image-board.c: Silence warning in select_ramdisk

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:50, Tom Rini  wrote:
>
> When building with clang we get a warning that rdaddr could be
> uninitialized in one case. While this cannot functionally happen, we can
> easily silence the warning.
>
> Signed-off-by: Tom Rini 
> ---
>  boot/image-board.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH 5/9] armv7: Use isb/dsb directly in start.S

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:50, Tom Rini  wrote:
>
> Toolchains which do not directly support using "isb" and "dsb" directly
> are no longer functionally supported in U-Boot. Furthermore, clang has
> for a long time warned about using the alternate form that we were.
> Update the code.
>
> Signed-off-by: Tom Rini 
> ---
>  arch/arm/cpu/armv7/start.S | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 4/9] arm: Centralize fixed register logic

2023-04-06 Thread Simon Glass
On Thu, 6 Apr 2023 at 11:50, Tom Rini  wrote:
>
> When building for ARM64, we need to pass -ffixed-x18 and otherwise pass
> -ffixed-r9. Rather than having this logic in two places, we can do this
> once in arch/arm/config.mk. Further, while gcc will ignore being passed
> both -ffixed-r9 and -ffixed-x18 and simply use -ffixed-x18, clang will
> note that -ffixed-r9 is not used. Remove this duplication to also remove
> the warning.
>
> Signed-off-by: Tom Rini 
> ---
>  arch/arm/config.mk   | 10 --
>  arch/arm/cpu/armv8/config.mk |  1 -
>  2 files changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] api: Rework menu, and make it depend on CC_IS_GCC

2023-04-06 Thread Simon Glass
On Fri, 7 Apr 2023 at 01:49, Tom Rini  wrote:
>
> We can only use the old U-Boot API for standalone applications when
> building U-Boot with GCC as it relies upon the "gd is a register" trick
> that only GCC supports. Further, rework the rest of the options so that
> they are in the API menu and only visible if API support is enabled.
>
> Reported-by: Heinrich Schuchardt 
> Signed-off-by: Tom Rini 
> ---
>  api/Kconfig | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [BUG] issues with new bootflow, uefi and virtio

2023-04-06 Thread Simon Glass
Hi Vincent,

On Thu, 6 Apr 2023 at 22:05, Vincent Stehlé  wrote:
>
> On Thu, Apr 06, 2023 at 06:38:16AM +1200, Simon Glass wrote:
> (virtio device number 31 vs. blk index 0)
> > This is strange. Can you try 'dm uclass' to see the sequence number
> > for the virtio device? I would expect it to be 0, but I might not
> > fully understand virtio.
>
> Hi Simon,
>
> Thank you for looking into this. Here is the `dm uclass' extract corresponding
> to virtio on this Qemu system:
>
>   uclass 126: virtio
>   0   * virtio_mmio@a00 @ 7ee977d0, seq 0
>   1   * virtio_mmio@a000200 @ 7ee97870, seq 1
>   2   * virtio_mmio@a000400 @ 7ee97910, seq 2
>   3   * virtio_mmio@a000600 @ 7ee979b0, seq 3
>   4   * virtio_mmio@a000800 @ 7ee97a50, seq 4
>   5   * virtio_mmio@a000a00 @ 7ee97af0, seq 5
>   6   * virtio_mmio@a000c00 @ 7ee97b90, seq 6
>   7   * virtio_mmio@a000e00 @ 7ee97c30, seq 7
>   8   * virtio_mmio@a001000 @ 7ee97cd0, seq 8
>   9   * virtio_mmio@a001200 @ 7ee97d70, seq 9
>   10  * virtio_mmio@a001400 @ 7ee97e10, seq 10
>   11  * virtio_mmio@a001600 @ 7ee97eb0, seq 11
>   12  * virtio_mmio@a001800 @ 7ee97f50, seq 12
>   13  * virtio_mmio@a001a00 @ 7ee97ff0, seq 13
>   14  * virtio_mmio@a001c00 @ 7ee98090, seq 14
>   15  * virtio_mmio@a001e00 @ 7ee98130, seq 15
>   16  * virtio_mmio@a002000 @ 7ee981d0, seq 16
>   17  * virtio_mmio@a002200 @ 7ee98270, seq 17
>   18  * virtio_mmio@a002400 @ 7ee98310, seq 18
>   19  * virtio_mmio@a002600 @ 7ee983b0, seq 19
>   20  * virtio_mmio@a002800 @ 7ee98450, seq 20
>   21  * virtio_mmio@a002a00 @ 7ee984f0, seq 21
>   22  * virtio_mmio@a002c00 @ 7ee98590, seq 22
>   23  * virtio_mmio@a002e00 @ 7ee98630, seq 23
>   24  * virtio_mmio@a003000 @ 7ee986d0, seq 24
>   25  * virtio_mmio@a003200 @ 7ee98770, seq 25
>   26  * virtio_mmio@a003400 @ 7ee98810, seq 26
>   27  * virtio_mmio@a003600 @ 7ee988b0, seq 27
>   28  * virtio_mmio@a003800 @ 7ee98950, seq 28
>   29  * virtio_mmio@a003a00 @ 7ee989f0, seq 29
>   30  * virtio_mmio@a003c00 @ 7ee98a90, seq 30
>   31  * virtio_mmio@a003e00 @ 7ee98b30, seq 31
>
> (issue with multiple virtio devices)

OK, thanks for that. I had no idea there would be lots of them.

> > Please also see this:
> >
> > https://patchwork.ozlabs.org/project/uboot/patch/20230402140231.v7.3.Ifa423a8f295b3c11e50821222b0db1e869d0c051@changeid/
> >
> > (or the whole series)
>
> Thank you for this patch!
>
> When combined with the patch from Mathew[1], it does indeed repair the case of
> efi boot with two virtio disks, specifically when the first virtio disk is the
> one we want to boot from.
> FWIW, the system will not boot when I invert the two virtio disks.

Is this because it only uses the first virtio device? You could check
your boot_targets variable. With standard boot you can use 'virtio'
instead of 'vritio0' and it will find any virtio devices.

>
> Best regards,
> Vincent.
>
> [1]: https://lists.denx.de/pipermail/u-boot/2023-April/514527.html

Regards,
Simon


Re: [BUG] issues with new bootflow, uefi and virtio

2023-04-06 Thread Simon Glass
Hi Mathew,

On Thu, 6 Apr 2023 at 12:25, Mathew McBride  wrote:
>
> Hi Vincent,
>
> On Thu, Apr 6, 2023, at 1:04 AM, Vincent Stehlé wrote:
> > Hi,
> >
> > I am hitting an issue with the new bootflow when booting with UEFI from a
> > virtio device on Qemu Arm.
> >
> > It seems the device number computation in efiload_read_file() does not work
> > in the general virtio case, where it will pick the virtio device number
> > instead of the block device index. On Qemu arm virt machine, many virtio
> > mmio devices are provisioned in the memory map and no assumption can be
> > made on the number of the actual virtio device in use in the general case.
> >
> > This is an extract of the output of `dm tree' on this platform, focused on
> > the virtio device from which I would like to boot:
> >
> >   virtio31  [ + ]   virtio-mmio |-- virtio_mmio@a003e00
> >   blk0  [ + ]   virtio-blk  |   |-- virtio-blk#31
> >   partition  0  [ + ]   blk_partition   |   |   |-- virtio-blk#31:1
> >   partition  1  [ + ]   blk_partition   |   |   `-- virtio-blk#31:2
> >   bootdev2  [ + ]   virtio_bootdev  |   `-- virtio-blk#31.bootdev
> >
> > In this extract the actual virtio device number is 31, as will be picked by
> > efiload_read_file(), but the desired block device index is zero, as would
> > be used with e.g. `ls virtio 0'.
>
> I came across the exact same issue a few days ago. Below is a patch which I 
> believe fixes the problem, by using the devnum of blk uclass (virtio 0) 
> instead of the sequence number of the parent udevice (e.g virtio-blk#35).
>
> Separately, the devnum was previously being parsed as a hex which meant 
> "virtio_blk#35" was actually being parsed as "virtio_blk#23". That confused 
> me for a while.
>
> If the patch looks good I can re-post it directly to the ML. I'm not 100% 
> sure that I got it right.
>
> In case the email mangles the patch, you can grab a diff here as well: 
> https://gitlab.com/traversetech/ls1088firmware/u-boot/-/commit/5ed3315b4a297f143fb84f44117b5b31e5617af5
>
> - Matt
>
> 
>
> From 5ed3315b4a297f143fb84f44117b5b31e5617af5 Mon Sep 17 00:00:00 2001
> From: Mathew McBride 
> Date: Wed, 5 Apr 2023 02:44:48 +
> Subject: [PATCH] bootstd: use blk uclass device numbers to set efi bootdev
>
> When loading a file from a block device, efiload_read_file
> was using the seq_num of the device (e.g "35" of virtio_blk#35)
> instead of the block device id (e.g what you get from running
> the corresponding device scan command, like "virtio 0")
>
> This cause EFI booting from these devices to fail as an
> invalid device number is passed to blk_get_device_part_str:
>
> Scanning bootdev 'virtio-blk#35.bootdev':
> distro_efi_read_bootflow_file start (efi,fname=)
> distro_efi_read_bootflow_file start (efi,fname=)
> setting bootdev virtio, 35, efi/boot/bootaa64.efi, beef9a40, 170800
> efi_dp_from_name calling blk_get_device_part_str
> dev=virtio devnr=35 path=efi/boot/bootaa64.efi
> blk_get_device_part_str (virtio,35)
> blk_get_device_by_str (virtio, 35)
> ** Bad device specification virtio 35 **
> Using default device tree: dtb/qemu-arm.dtb
> No device tree available
> 0  efi  ready   virtio   1  virtio-blk#35.bootdev.par 
> efi/boot/bootaa64.efi
> ** Booting bootflow 'virtio-blk#35.bootdev.part_1' with efi
> blk_get_device_part_str (virtio,0:1)
> blk_get_device_by_str (virtio, 0)
> No UEFI binary known at beef9a40 (image 
> buf=beef9a40,addr=)
> Boot failed (err=-22)
>
> Signed-off-by: Mathew McBride 
> ---
>  boot/bootmeth_efi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index 6a97ac02ff..bc106aa736 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -117,7 +117,7 @@ static int efiload_read_file(struct blk_desc *desc, 
> struct bootflow *bflow)
>  * this can go away.
>  */
> media_dev = dev_get_parent(bflow->dev);
> -   snprintf(devnum_str, sizeof(devnum_str), "%x", dev_seq(media_dev));
> +   snprintf(devnum_str, sizeof(devnum_str), "%d", desc->devnum);

Yes this looks right to me.  I am actually changing the same line in a
current series, so I can pick up this patch and include it in the
series.

>
> strlcpy(dirname, bflow->fname, sizeof(dirname));
> last_slash = strrchr(dirname, '/');
> --
> 2.30.1
>
>
>

Regards,
Simon


Re: [PATCH] ARM: configs: imx8mm: Sync i.MX8M Mini Toradex Verdin and Menlo board configs

2023-04-06 Thread Peng Fan




On 4/6/2023 7:51 AM, Marek Vasut wrote:

Synchronize the i.MX8M Mini Toradex Verdin based Menlo board config
with i.MX8M Mini Toradex Verdin carrier board. This enables DM MDIO,
eMMC HS modes, TMU for thermal monitoring, LTO and multiple commands
(hexdump, pmic, read, time).

Signed-off-by: Marek Vasut 


Reviewed-by: Peng Fan 


---
Cc: Marek Vasut 
Cc: Olaf Mandel 
Cc: Peng Fan 
Cc: Stefano Babic 
---
  configs/imx8mm-mx8menlo_defconfig | 20 ++--
  1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/configs/imx8mm-mx8menlo_defconfig 
b/configs/imx8mm-mx8menlo_defconfig
index 0a374aab06d..0bd852a77b9 100644
--- a/configs/imx8mm-mx8menlo_defconfig
+++ b/configs/imx8mm-mx8menlo_defconfig
@@ -12,6 +12,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx8mm-mx8menlo"
  CONFIG_SPL_TEXT_BASE=0x7E1000
  CONFIG_TARGET_IMX8MM_MX8MENLO=y
  CONFIG_SYS_PROMPT="Verdin iMX8MM # "
+CONFIG_OF_LIBFDT_OVERLAY=y
  CONFIG_SPL_MMC=y
  CONFIG_SPL_SERIAL=y
  CONFIG_SPL_DRIVERS_MISC=y
@@ -24,6 +25,7 @@ CONFIG_ENV_OFFSET_REDUND=0xDE00
  CONFIG_SYS_LOAD_ADDR=0x4048
  CONFIG_SYS_MEMTEST_START=0x4000
  CONFIG_SYS_MEMTEST_END=0x8000
+CONFIG_LTO=y
  CONFIG_SYS_MONITOR_LEN=524288
  CONFIG_FIT=y
  CONFIG_FIT_EXTERNAL_OFFSET=0x3000
@@ -61,18 +63,23 @@ CONFIG_SYS_PBSIZE=2081
  CONFIG_CMD_ASKENV=y
  # CONFIG_CMD_EXPORTENV is not set
  # CONFIG_CMD_CRC32 is not set
+CONFIG_CMD_MD5SUM=y
+CONFIG_MD5SUM_VERIFY=y
  CONFIG_CMD_MEMTEST=y
  CONFIG_CMD_CLK=y
  CONFIG_CMD_FUSE=y
  CONFIG_CMD_GPIO=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
+CONFIG_CMD_READ=y
  CONFIG_CMD_USB=y
  CONFIG_CMD_USB_SDP=y
  CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_BOOTCOUNT=y
  CONFIG_CMD_CACHE=y
+CONFIG_CMD_TIME=y
  CONFIG_CMD_UUID=y
+CONFIG_CMD_PMIC=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_CMD_BTRFS=y
  CONFIG_CMD_EXT4_WRITE=y
@@ -87,7 +94,7 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
  CONFIG_SYS_MMC_ENV_PART=1
  CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
  CONFIG_USE_ETHPRIME=y
-CONFIG_ETHPRIME="FEC"
+CONFIG_ETHPRIME="eth0"
  CONFIG_VERSION_VARIABLE=y
  CONFIG_IP_DEFRAG=y
  CONFIG_TFTP_BLOCKSIZE=4096
@@ -104,11 +111,19 @@ CONFIG_DM_I2C=y
  CONFIG_MISC=y
  CONFIG_I2C_EEPROM=y
  CONFIG_SUPPORT_EMMC_BOOT=y
+CONFIG_MMC_IO_VOLTAGE=y
+CONFIG_SPL_MMC_IO_VOLTAGE=y
+CONFIG_MMC_UHS_SUPPORT=y
+CONFIG_SPL_MMC_UHS_SUPPORT=y
+CONFIG_MMC_HS400_ES_SUPPORT=y
+CONFIG_MMC_HS400_SUPPORT=y
+CONFIG_SPL_MMC_HS400_SUPPORT=y
  CONFIG_FSL_USDHC=y
  CONFIG_PHYLIB=y
  CONFIG_PHY_ADDR_ENABLE=y
  CONFIG_PHY_MICREL=y
  CONFIG_PHY_MICREL_KSZ90X1=y
+CONFIG_DM_MDIO=y
  CONFIG_FEC_MXC=y
  CONFIG_MII=y
  CONFIG_SPL_PHY=y
@@ -131,6 +146,7 @@ CONFIG_SPL_SYSRESET=y
  CONFIG_SYSRESET_PSCI=y
  CONFIG_SYSRESET_WATCHDOG=y
  CONFIG_DM_THERMAL=y
+CONFIG_IMX_TMU=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_MXC_USB_OTG_HACTIVE=y
@@ -143,4 +159,4 @@ CONFIG_CI_UDC=y
  CONFIG_SDP_LOADADDR=0x4040
  CONFIG_USB_GADGET_DOWNLOAD=y
  CONFIG_IMX_WATCHDOG=y
-CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_HEXDUMP=y


Re: [PATCH 13/17] mmc: rockchip_sdhci: Add support for RK3588

2023-04-06 Thread Shawn Lin

在 2023/4/4 18:01, Kever Yang 写道:

Add Shawn and Yifeng.

Please help review this patch.


Thanks,
- Kever
On 2023/4/4 04:48, Jonas Karlman wrote:

Add support for RK3588 to the sdhci driver. RK3588 has the inverter flag
in TXCLK reg instead of RXCLK and also make use of a new CMDOUT reg.
Add and use a quirks field to support such quirks.

Signed-off-by: Jonas Karlman 


Reviewed-by: Shawn Lin 



---
  drivers/mmc/rockchip_sdhci.c | 62 ++--
  1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c
index 12a616d3dfb8..9178bc00b6b8 100644
--- a/drivers/mmc/rockchip_sdhci.c
+++ b/drivers/mmc/rockchip_sdhci.c
@@ -56,6 +56,7 @@
  #define DWCMSHC_EMMC_DLL_RXCLK    0x804
  #define DWCMSHC_EMMC_DLL_TXCLK    0x808
  #define DWCMSHC_EMMC_DLL_STRBIN    0x80c
+#define DWCMSHC_EMMC_DLL_CMDOUT    0x810
  #define DWCMSHC_EMMC_DLL_STATUS0    0x840
  #define DWCMSHC_EMMC_DLL_STATUS1    0x844
  #define DWCMSHC_EMMC_DLL_START    BIT(0)
@@ -70,18 +71,28 @@
  #define DLL_RXCLK_NO_INVERTER    BIT(29)
  #define DLL_RXCLK_ORI_GATE    BIT(31)
  #define DLL_TXCLK_TAPNUM_DEFAULT    0x10
+#define DLL_TXCLK_TAPNUM_90_DEGREES    0x9
  #define DLL_TXCLK_TAPNUM_FROM_SW    BIT(24)
+#define DLL_TXCLK_NO_INVERTER    BIT(29)
  #define DLL_STRBIN_TAPNUM_DEFAULT    0x4
  #define DLL_STRBIN_TAPNUM_FROM_SW    BIT(24)
  #define DLL_STRBIN_DELAY_NUM_SEL    BIT(26)
  #define DLL_STRBIN_DELAY_NUM_OFFSET    16
  #define DLL_STRBIN_DELAY_NUM_DEFAULT    0x10
+#define DLL_CMDOUT_TAPNUM_90_DEGREES    0x8
+#define DLL_CMDOUT_TAPNUM_FROM_SW    BIT(24)
+#define DLL_CMDOUT_SRC_CLK_NEG    BIT(28)
+#define DLL_CMDOUT_EN_SRC_CLK_NEG    BIT(29)
+#define DLL_CMDOUT_BOTH_CLK_EDGE    BIT(30)
  #define DLL_LOCK_WO_TMOUT(x) \
  x) & DWCMSHC_EMMC_DLL_LOCKED) == DWCMSHC_EMMC_DLL_LOCKED) && \
  (((x) & DWCMSHC_EMMC_DLL_TIMEOUT) == 0))
  #define ROCKCHIP_MAX_CLKS    3
+#define QUIRK_INVERTER_FLAG_IN_RXCLK    BIT(0)
+#define QUIRK_HAS_DLL_CMDOUT    BIT(1)
+
  struct rockchip_sdhc_plat {
  struct mmc_config cfg;
  struct mmc mmc;
@@ -99,6 +110,7 @@ struct rockchip_sdhc {
  void *base;
  struct rockchip_emmc_phy *phy;
  struct clk emmc_clk;
+    u8 txclk_tapnum;
  };
  struct sdhci_data {
@@ -144,6 +156,8 @@ struct sdhci_data {
   * Return: 0 if successful, -ve on error
   */
  int (*set_enhanced_strobe)(struct sdhci_host *host);
+
+    u32 quirks;
  };
  static void rk3399_emmc_phy_power_on(struct rockchip_emmc_phy *phy, 
u32 clock)
@@ -294,6 +308,10 @@ static void rk3568_sdhci_set_clock(struct 
sdhci_host *host, u32 div)
  static int rk3568_sdhci_config_dll(struct sdhci_host *host, u32 
clock, bool enable)

  {
+    struct rockchip_sdhc *priv = container_of(host, struct 
rockchip_sdhc, host);
+    struct sdhci_data *data = (struct sdhci_data 
*)dev_get_driver_data(priv->dev);

+    struct mmc *mmc = host->mmc;
+    u8 txclk_tapnum = DLL_TXCLK_TAPNUM_DEFAULT;
  int val, ret;
  u32 extra;
@@ -318,12 +336,33 @@ static int rk3568_sdhci_config_dll(struct 
sdhci_host *host, u32 clock, bool enab

  if (ret)
  return ret;
-    extra = DWCMSHC_EMMC_DLL_DLYENA | DLL_RXCLK_NO_INVERTER;
+    extra = DWCMSHC_EMMC_DLL_DLYENA | DLL_RXCLK_ORI_GATE;
+    if (data->quirks & QUIRK_INVERTER_FLAG_IN_RXCLK)
+    extra |= DLL_RXCLK_NO_INVERTER;
  sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_RXCLK);
+    if (mmc->selected_mode == MMC_HS_200 ||
+    mmc->selected_mode == MMC_HS_400 ||
+    mmc->selected_mode == MMC_HS_400_ES)
+    txclk_tapnum = priv->txclk_tapnum;
+
+    if ((data->quirks & QUIRK_HAS_DLL_CMDOUT) &&
+    (mmc->selected_mode == MMC_HS_400 ||
+ mmc->selected_mode == MMC_HS_400_ES)) {
+    txclk_tapnum = DLL_TXCLK_TAPNUM_90_DEGREES;
+
+    extra = DLL_CMDOUT_SRC_CLK_NEG |
+    DLL_CMDOUT_BOTH_CLK_EDGE |
+    DWCMSHC_EMMC_DLL_DLYENA |
+    DLL_CMDOUT_TAPNUM_90_DEGREES |
+    DLL_CMDOUT_TAPNUM_FROM_SW;
+    sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_CMDOUT);
+    }
+
  extra = DWCMSHC_EMMC_DLL_DLYENA |
-    DLL_TXCLK_TAPNUM_DEFAULT |
-    DLL_TXCLK_TAPNUM_FROM_SW;
+    DLL_TXCLK_TAPNUM_FROM_SW |
+    DLL_TXCLK_NO_INVERTER |
+    txclk_tapnum;
  sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_TXCLK);
  extra = DWCMSHC_EMMC_DLL_DLYENA |
@@ -339,6 +378,8 @@ static int rk3568_sdhci_config_dll(struct 
sdhci_host *host, u32 clock, bool enab

  sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_CTRL);
  sdhci_writel(host, DLL_RXCLK_ORI_GATE, DWCMSHC_EMMC_DLL_RXCLK);
  sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_TXCLK);
+    if (data->quirks & QUIRK_HAS_DLL_CMDOUT)
+    sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_CMDOUT);
  /*
   * Before

Re: [PATCH] mmc: fsl_esdhc: Fix enablement of UHS mode

2023-04-06 Thread Peng Fan




On 4/6/2023 8:14 PM, Fabio Estevam wrote:

From: Fabio Estevam 

Since commit 1a7904fdfa7d ("mmc: fsl_esdhc_imx: Use esdhc_soc_data flags
to set host caps") the following SD card error is observed on an imx7d-sdb
board:

U-Boot 2023.04-00652-g487e42f7bc5e (Apr 05 2023 - 22:14:21 -0300)

CPU:   Freescale i.MX7D rev1.0 1000 MHz (running at 792 MHz)
CPU:   Commercial temperature grade (0C to 95C) at 35C
Reset cause: POR
Model: Freescale i.MX7 SabreSD Board
Board: i.MX7D SABRESD in non-secure mode
DRAM:  1 GiB
Core:  100 devices, 19 uclasses, devicetree: separate
PMIC: PFUZE3000 DEV_ID=0x30 REV_ID=0x10
MMC:   FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2
Loading Environment from MMC... Card did not respond to voltage select! : -110
*** Warning - No block device, using default environment

Fix the problem by only asserting the UHS_CAPS when supports_uhs() is true
instead of doing it unconditionally, only based on the defconfig option.

Signed-off-by: Fabio Estevam 
---
  drivers/mmc/fsl_esdhc_imx.c | 6 +-
  1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
index 66caf683f741..bfc94d2a5326 100644
--- a/drivers/mmc/fsl_esdhc_imx.c
+++ b/drivers/mmc/fsl_esdhc_imx.c
@@ -1258,11 +1258,7 @@ static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
esdhc_write32(®s->tuning_ctrl, val);
}
  
-		/*

-* UHS doesn't have explicit ESDHC flags, so if it's
-* not supported, disable it in config.
-*/
-   if (CONFIG_IS_ENABLED(MMC_UHS_SUPPORT))
+   if (CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) && 
supports_uhs(cfg->host_caps))
cfg->host_caps |= UHS_CAPS;


The supports_uhs is as below, so this condition check will never have 
UHS_CAPS set even MMC_UHS_SUPPORT selected. This seems not correct fix.


static inline bool supports_uhs(uint caps)
{
#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
return (caps & UHS_CAPS) ? true : false;
#else
return false;
#endif
}

Regards,
Peng.

  
  		if (CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)) {


Re: [PATCH 1/8] riscv: Optimize source end address calculation in start.S

2023-04-06 Thread Bin Meng
On Thu, Mar 30, 2023 at 8:36 PM Bin Meng  wrote:
>
> The __bss_start is the source end address hence load its address
> directly into register 't2' for optimization.
>
> Signed-off-by: Bin Meng 
> ---
>
>  arch/riscv/cpu/start.S | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S
> index 4687bca3c9..3c8344c345 100644
> --- a/arch/riscv/cpu/start.S
> +++ b/arch/riscv/cpu/start.S
> @@ -283,9 +283,7 @@ stack_setup:
> beq t0, s4, clear_bss   /* skip relocation */
>
> mv  t1, s4  /* t1 <- scratch for copy_loop */
> -   la  t3, __bss_start
> -   sub t3, t3, t0  /* t3 <- __bss_start_ofs */
> -   add t2, t0, t3  /* t2 <- source end address */
> +   la  t2, __bss_start /* t2 <- source end address */
>
>  copy_loop:
> LREGt5, 0(t0)
> --

Ping for this series?


Re: [PATCH 2/2] efi_loader: Fix warnings on unaligned accesses

2023-04-06 Thread Tom Rini
On Fri, Apr 07, 2023 at 10:46:08AM +0900, AKASHI Takahiro wrote:
> Hi Ilias,
> 
> On Thu, Apr 06, 2023 at 10:37:07PM +0300, Ilias Apalodimas wrote:
> > Tom reports that when building with clang we see this warning:
> > field guid within 'struct efi_hii_keyboard_layout' is less aligned than 
> > 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being 
> > packed, which can lead to unaligned accesses [-Wunaligned-access]
> > 
> > This happens because 'struct efi_hii_keyboard_layout' is defined as
> > packed while efi_guid_t is 32bit aligned.
> 
> There are a couple of 'struct' definitions which are *packed*
> and contain an 'efi_guid_t' member in efi_api.h.
> If 'efi_hii_keyboard_layout' is the only place that causes a clang warning,
> we need a more specific explanation to clarify the problem.
> 
> > However the EFI spec describes the EFI_GUID as
> > "128-bit buffer containing a unique identifier value.
> > Unless otherwise specified aligned on a 64-bit boundary"
> 
> That's right, but this text in this context may sound misleading.
> (It doesn't explain why 'efi_guid_t' is 32-bit aligned.)

When we build for qemu_arm64 another one of the instances pops up. My
first guess is that we have unused parts of the ABI and so while the
code would trigger the warning, it's not referenced and so doesn't ?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] arm: mx6: module_fuse: fix build failure due to wrong argument name

2023-04-06 Thread Peng Fan




On 4/7/2023 12:17 AM, Giulio Benetti wrote:

nodeoff variable should be variable off returned by fdt_path_offset() so
let's rename it to off.

Signed-off-by: Giulio Benetti 


Reviewed-by: Peng Fan 


Re: [PATCH 2/2] efi_loader: Fix warnings on unaligned accesses

2023-04-06 Thread AKASHI Takahiro
Hi Ilias,

On Thu, Apr 06, 2023 at 10:37:07PM +0300, Ilias Apalodimas wrote:
> Tom reports that when building with clang we see this warning:
> field guid within 'struct efi_hii_keyboard_layout' is less aligned than 
> 'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being 
> packed, which can lead to unaligned accesses [-Wunaligned-access]
> 
> This happens because 'struct efi_hii_keyboard_layout' is defined as
> packed while efi_guid_t is 32bit aligned.

There are a couple of 'struct' definitions which are *packed*
and contain an 'efi_guid_t' member in efi_api.h.
If 'efi_hii_keyboard_layout' is the only place that causes a clang warning,
we need a more specific explanation to clarify the problem.

> However the EFI spec describes the EFI_GUID as
> "128-bit buffer containing a unique identifier value.
> Unless otherwise specified aligned on a 64-bit boundary"

That's right, but this text in this context may sound misleading.
(It doesn't explain why 'efi_guid_t' is 32-bit aligned.)

-Takahiro Akashi

> 
> So convert the efi_guid_t -> u8 b[16] here and skip the alignment
> requirements.
> 
> Reported-by: Tom Rini 
> Suggested-by: Heinrich Schuchardt 
> Signed-off-by: Ilias Apalodimas 
> ---
>  include/efi_api.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/efi_api.h b/include/efi_api.h
> index 2fd0221c1c77..b84b577bd7b5 100644
> --- a/include/efi_api.h
> +++ b/include/efi_api.h
> @@ -1170,7 +1170,7 @@ struct efi_key_descriptor {
>  
>  struct efi_hii_keyboard_layout {
>   u16 layout_length;
> - efi_guid_t guid;
> + u8 guid[16];
>   u32 layout_descriptor_string_offset;
>   u8 descriptor_count;
>   /* struct efi_key_descriptor descriptors[]; follows here */
> -- 
> 2.39.2
> 


Re: [PATCH] ddr: marvell: a38x: Perform DDR training sequence again for 2nd boot

2023-04-06 Thread Tony Dinh
Hi Pali,

Could you review this patch?

Thanks,
Tony

On Sun, Apr 2, 2023 at 9:42 PM Tony Dinh  wrote:
>
> - DDR Training sequence happens very fast. The speedup in boot time is
> negligible by skipping the training sequence during 2nd boot or after.
> So remove the check and skip.
> - This change improves the robustness of DDR training. If u-boot crashed
> during DDR training, the training could be left in a limbo state, where
> the BootROM has recorded that it is already in a 2nd boot. The training
> must be repeated in this scenario to get out of this limbo state, but due
> to the check it cannot be performed.
>
> Signed-off-by: Tony Dinh 
> ---
>
>  drivers/ddr/marvell/a38x/mv_ddr_plat.c | 7 ---
>  1 file changed, 7 deletions(-)
>
> diff --git a/drivers/ddr/marvell/a38x/mv_ddr_plat.c 
> b/drivers/ddr/marvell/a38x/mv_ddr_plat.c
> index 6e7949ac72..8ec9fb0874 100644
> --- a/drivers/ddr/marvell/a38x/mv_ddr_plat.c
> +++ b/drivers/ddr/marvell/a38x/mv_ddr_plat.c
> @@ -1363,13 +1363,6 @@ int mv_ddr_pre_training_soc_config(const char 
> *ddr_type)
> DRAM_RESET_MASK_MASKED << DRAM_RESET_MASK_OFFS);
> }
>
> -   /* Check if DRAM is already initialized  */
> -   if (reg_read(REG_BOOTROM_ROUTINE_ADDR) &
> -   (1 << REG_BOOTROM_ROUTINE_DRAM_INIT_OFFS)) {
> -   printf("%s Training Sequence - 2nd boot - Skip\n", ddr_type);
> -   return MV_OK;
> -   }
> -
> /* Fix read ready phases for all SOC in reg 0x15c8 */
> reg_val = reg_read(TRAINING_DBG_3_REG);
>
> --
> 2.30.2
>


Re: [PATCH 1/1] net: replace /* Fall through */

2023-04-06 Thread Tom Rini
On Sat, Apr 01, 2023 at 09:30:05AM +0200, Heinrich Schuchardt wrote:

> gcc 12 does not understand /* Fall through */.
> Use the fallthrough macro instead.
> 
> Fallthrough at the start of a switch statement makes no sense.
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Ramon Fried 
> Reviewed-by: Simon Glass 
[snip]
> @@ -1484,11 +1483,11 @@ static int net_check_prereq(enum proto_t protocol)
>   puts("*** ERROR: `serverip' not set\n");
>   return 1;
>   }
> + fallthrough;
>  #if  defined(CONFIG_CMD_PING) || \
>   defined(CONFIG_CMD_DNS) || defined(CONFIG_PROT_UDP)
>  common:
>  #endif

This leads to:
net/net.c:1486:3: error: fallthrough annotation does not directly precede 
switch label
with clang.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 3/4] rockchip: rk35xx: Fix boot with a large fdt blob

2023-04-06 Thread Jagan Teki
On Wed, 22 Mar 2023 at 03:14, Jonas Karlman  wrote:
>
> The TF-A blobs used to boot RK3568 and RK3588 boards is based on atf
> v2.3. Mainline atf v2.3 contains an issue that could lead to a crash
> when it fails to parse the fdt blob being passed as the platform param.
> An issue that was fixed in atf v2.4.
>
> The vendor TF-A seem to suffer from a similar issue, and this prevents
> booting when fdt blob is large enough to trigger this condition.
>
> Fix this by implying SPL_ATF_NO_PLATFORM_PARAM to let u-boot pass a
> NULL pointer instead of the fdt blob as the platform param.
>
> This fixes booting Radxa ROCK 3A after recent sync of device tree.
>
> Fixes: 073d911ae64a ("rockchip: rk3568-rock-3a: Sync device tree from linux")
> Signed-off-by: Jonas Karlman 
> ---
> v2:
> - New patch
>
>  arch/arm/mach-rockchip/Kconfig | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
> index e5ac58ae60b5..d7e3784ba113 100644
> --- a/arch/arm/mach-rockchip/Kconfig
> +++ b/arch/arm/mach-rockchip/Kconfig
> @@ -288,6 +288,7 @@ config ROCKCHIP_RK3568
> select BOARD_LATE_INIT
> select DM_REGULATOR_FIXED
> select DM_RESET
> +   imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
> imply ROCKCHIP_COMMON_BOARD
> imply ROCKCHIP_OTP
> imply MISC_INIT_R
> @@ -309,6 +310,7 @@ config ROCKCHIP_RK3588

How it related to 3588, couldn't reproduce it from my end at least.
I'm using rk3588_bl31_v1.27.elf from rkbin.

Jagan.


[PATCH 2/2] efi_loader: Fix warnings on unaligned accesses

2023-04-06 Thread Ilias Apalodimas
Tom reports that when building with clang we see this warning:
field guid within 'struct efi_hii_keyboard_layout' is less aligned than 
'efi_guid_t' and is usually due to 'struct efi_hii_keyboard_layout' being 
packed, which can lead to unaligned accesses [-Wunaligned-access]

This happens because 'struct efi_hii_keyboard_layout' is defined as
packed while efi_guid_t is 32bit aligned.

However the EFI spec describes the EFI_GUID as
"128-bit buffer containing a unique identifier value.
Unless otherwise specified aligned on a 64-bit boundary"

So convert the efi_guid_t -> u8 b[16] here and skip the alignment
requirements.

Reported-by: Tom Rini 
Suggested-by: Heinrich Schuchardt 
Signed-off-by: Ilias Apalodimas 
---
 include/efi_api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 2fd0221c1c77..b84b577bd7b5 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1170,7 +1170,7 @@ struct efi_key_descriptor {
 
 struct efi_hii_keyboard_layout {
u16 layout_length;
-   efi_guid_t guid;
+   u8 guid[16];
u32 layout_descriptor_string_offset;
u8 descriptor_count;
/* struct efi_key_descriptor descriptors[]; follows here */
-- 
2.39.2



[PATCH 1/2] efi_loader: Fix flexible array member definitions

2023-04-06 Thread Ilias Apalodimas
When a structure contains a flexible array member, it is not supposed to be
included in arrays or other structs.
Quoting the C spec [0]
"Such a structure (and any union containing, possibly recursively, a
member that is such a structure) shall not be a member of a structure
or an element of an array."

IOW efi_hii_keyboard_layout should not include
struct efi_key_descriptor descriptors[]; since we use it at the
declaration of struct efi_hii_keyboard_package.

[0] https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf
chapter 6.7.2.1

Signed-off-by: Ilias Apalodimas 
---
 include/efi_api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index dc6e5ce236c9..2fd0221c1c77 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1173,7 +1173,7 @@ struct efi_hii_keyboard_layout {
efi_guid_t guid;
u32 layout_descriptor_string_offset;
u8 descriptor_count;
-   struct efi_key_descriptor descriptors[];
+   /* struct efi_key_descriptor descriptors[]; follows here */
 } __packed;

 struct efi_hii_keyboard_package {
--
2.39.2



Re: [PATCH] arm: mach-k3: am642: move do_dt_magic() after sysfw loading

2023-04-06 Thread Bryan Brattlof
Hi Christian!

On March 28, 2023 thus sayeth Christian Gmeiner:
> Makes it possible to use e.g mcu_spi0 for custom board detection.
> 
> Signed-off-by: Christian Gmeiner 
> ---
>  arch/arm/mach-k3/am642_init.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>

I had to pick up the patch from Vignesh[0] to test this out, however 
this works for me.

Reviewed-by: Bryan Brattlof 

~Bryan

[0]https://lore.kernel.org/u-boot/20230406075936.2590125-1-vigne...@ti.com/


Re: [PATCH] arm: mach-k3: Workaround errata ID i2331

2023-04-06 Thread Bryan Brattlof
Hi Vignesh!

On April  6, 2023 thus sayeth Vignesh Raghavendra:
> From: Nitin Yadav 
> 
> Errata doc: https://www.ti.com/lit/pdf/sprz457
> Errata ID i2331 CPSW: Device lockup when reading CPSW registers
> 
> Details: A device lockup can occur during the second read of any CPSW
> subsystem register after any MAIN domain power on reset (POR). A MAIN
> domain POR occurs using the hardware MCU_PORz signal, or via software
> using CTRLMMR_RST_CTRL.SW_MAIN_POR or CTRLMMR_MCU_RST_CTRL.SW_MAIN_POR.
> After these resets, the processor and internal bus structures may get
> into a state which is only recoverable with full device reset using
> MCU_PORz.
> Due to this errata, Ethernet boot should not be used on this device.
> 
> Workaround(s): To avoid the lockup, a warm reset should be issued after
> a MAIN domain POR and before any access to the CPSW registers. The warm
> reset realigns internal clocks and prevents the lockup from happening.
> Workaround above errata by calling do_reset() in case of cold boot in
> order to trigger warm reset. This needs enabling SYSRESET driver in R5
> SPL to enable TI SCI reset driver.
> 
> Signed-off-by: Nitin Yadav 
> Signed-off-by: Vignesh Raghavendra 
> ---
>  arch/arm/mach-k3/am642_init.c  | 33 +
>  configs/am64x_evm_r5_defconfig |  3 +++
>  2 files changed, 36 insertions(+)
>

Thanks for sending this! 

Reviewed-by: Bryan Brattlof 

~Bryan


[PATCH v2 8/8] configs: am62x_evm_*: Enable USB and DFU support

2023-04-06 Thread Sjoerd Simons
Enable USB host as well as USB gadget and DFU support for a53; For the
r5 due to the smaller available size create a new config just for
DFU support

Signed-off-by: Sjoerd Simons 

---

Changes in v2:
- Create a seperate defconfig for R5

 configs/am62x_evm_a53_defconfig   |  35 +++-
 configs/am62x_evm_r5_usbdfu_defconfig | 116 ++
 2 files changed, 148 insertions(+), 3 deletions(-)
 create mode 100644 configs/am62x_evm_r5_usbdfu_defconfig

diff --git a/configs/am62x_evm_a53_defconfig b/configs/am62x_evm_a53_defconfig
index cc9c8eab3e3..7dbf2f54050 100644
--- a/configs/am62x_evm_a53_defconfig
+++ b/configs/am62x_evm_a53_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARM=y
 CONFIG_ARCH_K3=y
+CONFIG_SYS_MALLOC_LEN=0x200
 CONFIG_SYS_MALLOC_F_LEN=0x8000
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
@@ -9,9 +10,11 @@ CONFIG_K3_ATF_LOAD_ADDR=0x9e78
 CONFIG_TARGET_AM625_A53_EVM=y
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x8048
+CONFIG_SF_DEFAULT_SPEED=2500
 CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="k3-am625-sk"
 CONFIG_SPL_TEXT_BASE=0x8008
+CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_DM_RESET=y
 CONFIG_SPL_MMC=y
 CONFIG_SPL_SERIAL=y
@@ -33,17 +36,23 @@ CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x1400
+CONFIG_SPL_ENV_SUPPORT=y
 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME="u-boot.img"
 CONFIG_SPL_DM_MAILBOX=y
 CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_POWER_DOMAIN=y
+CONFIG_SPL_RAM_SUPPORT=y
+CONFIG_SPL_RAM_DEVICE=y
 # CONFIG_SPL_SPI_FLASH_TINY is not set
 CONFIG_SPL_SPI_FLASH_SFDP_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x28
+CONFIG_SPL_USB_GADGET=y
+CONFIG_SPL_DFU=y
 CONFIG_SPL_YMODEM_SUPPORT=y
-CONFIG_SYS_BOOTM_LEN=0x80
+CONFIG_CMD_DFU=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_MULTI_DTB_FIT=y
@@ -54,10 +63,17 @@ CONFIG_SPL_DM=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_REGMAP=y
 CONFIG_SPL_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_SPL_SYSCON=y
 CONFIG_SPL_OF_TRANSLATE=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
 CONFIG_CLK_TI_SCI=y
+CONFIG_DFU_MMC=y
+CONFIG_DFU_RAM=y
+CONFIG_DFU_SF=y
+CONFIG_SYS_DFU_DATA_BUF_SIZE=0x5000
+CONFIG_SYS_DFU_MAX_FILE_SIZE=0x80
 CONFIG_DMA_CHANNELS=y
 CONFIG_TI_K3_NAVSS_UDMA=y
 CONFIG_TI_SCI_PROTOCOL=y
@@ -68,7 +84,6 @@ CONFIG_MMC_SDHCI_ADMA=y
 CONFIG_SPL_MMC_SDHCI_ADMA=y
 CONFIG_MMC_SDHCI_AM654=y
 CONFIG_DM_SPI_FLASH=y
-CONFIG_SF_DEFAULT_SPEED=2500
 CONFIG_SPI_FLASH_SFDP_SUPPORT=y
 CONFIG_SPI_FLASH_SOFT_RESET=y
 CONFIG_SPI_FLASH_SOFT_RESET_ON_BOOT=y
@@ -96,5 +111,19 @@ CONFIG_CADENCE_QSPI=y
 CONFIG_SYSRESET=y
 CONFIG_SPL_SYSRESET=y
 CONFIG_SYSRESET_TI_SCI=y
+CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
+CONFIG_SPL_DM_USB_GADGET=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_DWC3=y
+CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GENERIC=y
+CONFIG_SPL_USB_DWC3_GENERIC=y
+CONFIG_SPL_USB_DWC3_AM62=y
+CONFIG_USB_DWC3_AM62=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0451
+CONFIG_USB_GADGET_PRODUCT_NUM=0x6165
+CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_FS_FAT_MAX_CLUSTSIZE=16384
-CONFIG_OF_LIBFDT_OVERLAY=y
diff --git a/configs/am62x_evm_r5_usbdfu_defconfig 
b/configs/am62x_evm_r5_usbdfu_defconfig
new file mode 100644
index 000..00a0821b6df
--- /dev/null
+++ b/configs/am62x_evm_r5_usbdfu_defconfig
@@ -0,0 +1,116 @@
+CONFIG_ARM=y
+CONFIG_ARCH_K3=y
+CONFIG_SYS_MALLOC_LEN=0x0800
+CONFIG_SYS_MALLOC_F_LEN=0x9000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_SOC_K3_AM625=y
+CONFIG_TARGET_AM625_R5_EVM=y
+CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
+CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x43c3a7f0
+CONFIG_ENV_SIZE=0x2
+CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="k3-am625-r5-sk"
+CONFIG_SPL_TEXT_BASE=0x43c0
+CONFIG_DM_RESET=y
+CONFIG_SPL_SERIAL=y
+CONFIG_SPL_DRIVERS_MISC=y
+CONFIG_SPL_STACK_R_ADDR=0x8200
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x7000
+CONFIG_SPL_SIZE_LIMIT=0x3A7F0
+CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x3500
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_SPL_LOAD_FIT_ADDRESS=0x8008
+CONFIG_SPL_FIT_IMAGE_POST_PROCESS=y
+# CONFIG_DISPLAY_CPUINFO is not set
+CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD=y
+CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC=y
+CONFIG_SPL_MAX_SIZE=0x3B000
+CONFIG_SPL_PAD_TO=0x0
+CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
+CONFIG_SPL_BSS_START_ADDR=0x43c3b000
+CONFIG_SPL_BSS_MAX_SIZE=0x3000
+CONFIG_SPL_SYS_REPORT_STACK_F_USAGE=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SYS_SPL_MALLOC=y
+CONFIG_HAS_CUSTOM_SPL_MALLOC_START=y
+CONFIG_CUSTOM_SYS_SPL_MALLOC_ADDR=0x8400
+CONFIG_SYS_SPL_MALLOC_SIZE=0x100
+CONFIG_SPL_EARLY_BSS=y
+CONFIG_SPL_ENV_SUPPORT=y
+CONFIG_SPL_DM_MAILBOX=y
+CONFIG_SPL_DM_RESET=y
+CONFIG_SPL_POWER_DOMAIN=y
+CONFIG_SPL_RAM_SUPPORT=y
+CONFIG_SPL_RAM_DEVICE=y
+CONFIG_SPL_REMOTEPROC=y
+CONFIG_SPL_USB_GADGET=y
+CONFIG_SPL_DFU=y
+C

[PATCH v2 7/8] arm: dts: k3-am625-sk: Enable usb ports in u-boot

2023-04-06 Thread Sjoerd Simons
Enable both usb0 as a peripheral for use with DFU and

Signed-off-by: Sjoerd Simons 

---

Changes in v2:
- Only enable usb port 0 DFU in SPL

 arch/arm/dts/k3-am625-sk-u-boot.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/dts/k3-am625-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
index 5f90a4b56f1..2746451572d 100644
--- a/arch/arm/dts/k3-am625-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
@@ -154,3 +154,14 @@
 &cpsw_port2 {
status = "disabled";
 };
+
+&usbss0 {
+   bootph-pre-ram;
+};
+
+&usb0 {
+   dr_mode = "peripheral";
+   /* Since role switching is not supported in U-Boot */
+   /delete-property/ extcon;
+   bootph-pre-ram;
+};
-- 
2.40.0



[PATCH v2 5/8] usb: dwc3: Add dwc3 glue driver for am62

2023-04-06 Thread Sjoerd Simons
Add glue code for TI AM62 to the dwc3 driver; Most code adopted from
TI vendor u-boot code.

Signed-off-by: Sjoerd Simons 

---

Changes in v2:
- Switch dwc3 glue to a seperate driver rather then in dwc-generic

 drivers/usb/dwc3/Kconfig |  14 
 drivers/usb/dwc3/Makefile|   1 +
 drivers/usb/dwc3/dwc3-am62.c | 127 +++
 3 files changed, 142 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-am62.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index c0c8c16fd9c..26a1e1770c5 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -37,6 +37,20 @@ config SPL_USB_DWC3_GENERIC
  Select this for Xilinx ZynqMP and similar Platforms.
  This wrapper supports Host and Peripheral operation modes.
 
+config SPL_USB_DWC3_AM62
+   bool "TI AM62 USB wrapper"
+   depends on SPL_DM_USB && SPL_USB_DWC3_GENERIC
+   help
+ Select this for TI AM62 Platforms.
+ This wrapper supports Host and Peripheral operation modes.
+
+config USB_DWC3_AM62
+   bool "TI AM62 USB wrapper"
+   depends on DM_USB && USB_DWC3_GENERIC
+   help
+ Select this for TI AM62 Platforms.
+ This wrapper supports Host and Peripheral operation modes.
+
 config USB_DWC3_MESON_G12A
bool "Amlogic Meson G12A USB wrapper"
depends on DM_USB && USB_DWC3 && ARCH_MESON
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 97b4f7191ca..a46b6824ab7 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -6,6 +6,7 @@ dwc3-y  := core.o
 
 obj-$(CONFIG_USB_DWC3_GADGET)  += gadget.o ep0.o
 
+obj-$(CONFIG_$(SPL_)USB_DWC3_AM62) += dwc3-am62.o
 obj-$(CONFIG_USB_DWC3_OMAP)+= dwc3-omap.o
 obj-$(CONFIG_USB_DWC3_MESON_G12A)  += dwc3-meson-g12a.o
 obj-$(CONFIG_USB_DWC3_MESON_GXL)   += dwc3-meson-gxl.o
diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c
new file mode 100644
index 000..20d99758b4f
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-am62.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TI AM62 specific glue layer for DWC3
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "dwc3-generic.h"
+
+void dwc3_ti_am62_glue_configure(struct udevice *dev, int index,
+enum usb_dr_mode mode)
+{
+#define USBSS_MODE_CONTROL 0x1c
+#define USBSS_PHY_CONFIG   0x8
+#define USBSS_PHY_VBUS_SEL_MASKGENMASK(2, 1)
+#define USBSS_PHY_VBUS_SEL_SHIFT   1
+#define USBSS_MODE_VALID   BIT(0)
+#define PHY_PLL_REFCLK_MASKGENMASK(3, 0)
+static const int dwc3_ti_am62_rate_table[] = { /* in KHZ */
+   9600,
+   1,
+   12000,
+   19200,
+   2,
+   24000,
+   25000,
+   26000,
+   38400,
+   4,
+   58000,
+   5,
+   52000,
+};
+
+   struct clk usb2_refclk;
+   int rate_code, i, ret;
+   unsigned long rate;
+   u32 reg;
+   void *usbss;
+   bool vbus_divider;
+   struct regmap *syscon;
+   struct ofnode_phandle_args args;
+
+   usbss = dev_remap_addr_index(dev, 0);
+   if (IS_ERR(usbss)) {
+   dev_err(dev, "can't map IOMEM resource\n");
+   return;
+   }
+
+   ret = clk_get_by_name(dev, "ref", &usb2_refclk);
+   if (ret) {
+   dev_err(dev, "can't get usb2_refclk\n");
+   return;
+   }
+
+   /* Calcuate the rate code */
+   rate = clk_get_rate(&usb2_refclk);
+   rate /= 1000;   /* To KHz */
+   for (i = 0; i < ARRAY_SIZE(dwc3_ti_am62_rate_table); i++) {
+   if (dwc3_ti_am62_rate_table[i] == rate)
+   break;
+   }
+
+   if (i == ARRAY_SIZE(dwc3_ti_am62_rate_table)) {
+   dev_err(dev, "unsupported usb2_refclk rate: %lu KHz\n", rate);
+   return;
+   }
+
+   rate_code = i;
+
+   /* Read the syscon property */
+   syscon = syscon_regmap_lookup_by_phandle(dev, 
"ti,syscon-phy-pll-refclk");
+   if (IS_ERR(syscon)) {
+   dev_err(dev, "unable to get ti,syscon-phy-pll-refclk regmap\n");
+   return;
+   }
+
+   ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), 
"ti,syscon-phy-pll-refclk", NULL, 1,
+0, &args);
+   if (ret)
+   return;
+
+   /* Program PHY PLL refclk by reading syscon property */
+   ret = regmap_update_bits(syscon, args.args[0], PHY_PLL_REFCLK_MASK, 
rate_code);
+   if (ret) {
+   dev_err(dev, "failed to set phy pll reference clock rate\n");
+   return;
+   }
+
+   /* VBUS divider select */
+   reg = readl(usbss + USBSS_PHY_CONFIG);
+   vbus_divider = dev_read_bool(dev, "ti,vbus-divider");
+   if (vbus_divider)
+   reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT;
+
+ 

[PATCH v2 6/8] configs: am62: Add configs for enabling USB in U-Boot

2023-04-06 Thread Sjoerd Simons
Add configs for enabling USB DFU in U-Boot.

Signed-off-by: Sjoerd Simons 

---

Changes in v2:
- Minimize config changes to just DFU configuration

 include/configs/am62x_evm.h | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/configs/am62x_evm.h b/include/configs/am62x_evm.h
index 7bf07809b05..d07da4ebae4 100644
--- a/include/configs/am62x_evm.h
+++ b/include/configs/am62x_evm.h
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 
 /* DDR Configuration */
 #define CFG_SYS_SDRAM_BASE10x88000
@@ -38,9 +39,16 @@
DISTRO_BOOT_DEV_PXE(func) \
DISTRO_BOOT_DEV_DHCP(func)
 
+#define EXTRA_ENV_DFUARGS \
+   DFU_ALT_INFO_MMC \
+   DFU_ALT_INFO_EMMC \
+   DFU_ALT_INFO_RAM \
+   DFU_ALT_INFO_OSPI
+
 /* Incorporate settings into the U-Boot environment */
 #define CFG_EXTRA_ENV_SETTINGS \
-   BOOTENV
+   BOOTENV \
+   EXTRA_ENV_DFUARGS
 
 /* Now for the remaining common defines */
 #include 
-- 
2.40.0



[PATCH v2 4/8] arm: dts: k3-am625-sk: Enable emmc in SPL

2023-04-06 Thread Sjoerd Simons
sdhci0 on the k3-am625-sk is the emmc, enable this in SPL as well to
allow booting from that media.

Signed-off-by: Sjoerd Simons 
Reviewed-by: Tom Rini 
---

(no changes since v1)

 arch/arm/dts/k3-am625-sk-u-boot.dtsi | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/dts/k3-am625-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
index 0def84b4cf0..5f90a4b56f1 100644
--- a/arch/arm/dts/k3-am625-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
@@ -92,6 +92,14 @@
bootph-pre-ram;
 };
 
+&sdhci0 {
+   bootph-pre-ram;
+};
+
+&main_mmc0_pins_default {
+   bootph-pre-ram;
+};
+
 &sdhci1 {
bootph-pre-ram;
 };
-- 
2.40.0



[PATCH v2 3/8] arm: dts: k3-am62: Bump dtsi from linux

2023-04-06 Thread Sjoerd Simons
Update the am62 and am625 device-trees from linux v6.3-rc5 This needed the 
following
tweaks to the u-boot specific dtsi as well:
- Switch tick-timer to the main_timer as it's now defined in the main dtsi
- Add mdio pins to the cpsw3g pinctrl. It moved to a subnode in the
  linux dtsi that u-boot doesn't use/support

Signed-off-by: Sjoerd Simons 

---

Changes in v2:
- Update dts sync to v6.3-rc5

 arch/arm/dts/k3-am62-main.dtsi   | 259 ---
 arch/arm/dts/k3-am62-mcu.dtsi|  49 +
 arch/arm/dts/k3-am62-wakeup.dtsi |   4 +-
 arch/arm/dts/k3-am625-r5-sk.dts  |   2 +-
 arch/arm/dts/k3-am625-sk-u-boot.dtsi |   8 +-
 arch/arm/dts/k3-am625-sk.dts |  95 +-
 arch/arm/dts/k3-am625.dtsi   |  52 ++
 7 files changed, 381 insertions(+), 88 deletions(-)

diff --git a/arch/arm/dts/k3-am62-main.dtsi b/arch/arm/dts/k3-am62-main.dtsi
index 4a42f1b2e31..ea683fd77d6 100644
--- a/arch/arm/dts/k3-am62-main.dtsi
+++ b/arch/arm/dts/k3-am62-main.dtsi
@@ -54,6 +54,12 @@
reg = <0x4044 0x8>;
#phy-cells = <1>;
};
+
+   epwm_tbclk: clock@4130 {
+   compatible = "ti,am62-epwm-tbclk", "syscon";
+   reg = <0x4130 0x4>;
+   #clock-cells = <1>;
+   };
};
 
dmss: bus@4800 {
@@ -144,8 +150,8 @@
compatible = "ti,k2g-sci";
ti,host-id = <12>;
mbox-names = "rx", "tx";
-   mboxes= <&secure_proxy_main 12>,
-   <&secure_proxy_main 13>;
+   mboxes = <&secure_proxy_main 12>,
+<&secure_proxy_main 13>;
reg-names = "debug_messages";
reg = <0x00 0x44043000 0x00 0xfe0>;
 
@@ -186,6 +192,102 @@
pinctrl-single,function-mask = <0x>;
};
 
+   main_timer0: timer@240 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x240 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 36 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 36 2>;
+   assigned-clock-parents = <&k3_clks 36 3>;
+   power-domains = <&k3_pds 36 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer1: timer@241 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x241 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 37 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 37 2>;
+   assigned-clock-parents = <&k3_clks 37 3>;
+   power-domains = <&k3_pds 37 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer2: timer@242 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x242 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 38 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 38 2>;
+   assigned-clock-parents = <&k3_clks 38 3>;
+   power-domains = <&k3_pds 38 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer3: timer@243 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x243 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 39 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 39 2>;
+   assigned-clock-parents = <&k3_clks 39 3>;
+   power-domains = <&k3_pds 39 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer4: timer@244 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x244 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 40 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 40 2>;
+   assigned-clock-parents = <&k3_clks 40 3>;
+   power-domains = <&k3_pds 40 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer5: timer@245 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x245 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 41 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 41 2>;
+   assigned-clock-parents = <&k3_clks 41 3>;
+   power-domains = <&k3_pds 41 TI_SCI_PD_EXCLUSIVE>;
+   ti,timer-pwm;
+   };
+
+   main_timer6: timer@246 {
+   compatible = "ti,am654-timer";
+   reg = <0x00 0x246 0x00 0x400>;
+   interrupts = ;
+   clocks = <&k3_clks 42 2>;
+   clock-names = "fck";
+   assigned-clocks = <&k3_clks 4

[PATCH v2 2/8] arm: mach-k3: am62: Add timer0 id to the dev list

2023-04-06 Thread Sjoerd Simons
Timer0 is used by u-boot as the tick timer; Add it to the soc devices
list so it can be enabled via the k3 power controller.

Signed-off-by: Sjoerd Simons 
Reviewed-by: Tom Rini 
---

(no changes since v1)

 arch/arm/mach-k3/am62x/dev-data.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-k3/am62x/dev-data.c 
b/arch/arm/mach-k3/am62x/dev-data.c
index 616d0650b9c..140dca4bd1d 100644
--- a/arch/arm/mach-k3/am62x/dev-data.c
+++ b/arch/arm/mach-k3/am62x/dev-data.c
@@ -58,6 +58,7 @@ static struct ti_dev soc_dev_list[] = {
PSC_DEV(161, &soc_lpsc_list[8]),
PSC_DEV(162, &soc_lpsc_list[9]),
PSC_DEV(75, &soc_lpsc_list[10]),
+   PSC_DEV(36, &soc_lpsc_list[11]),
PSC_DEV(102, &soc_lpsc_list[11]),
PSC_DEV(146, &soc_lpsc_list[11]),
PSC_DEV(13, &soc_lpsc_list[12]),
-- 
2.40.0



[PATCH v2 1/8] omap: timer: add ti,am654-timer compatibility

2023-04-06 Thread Sjoerd Simons
THe TI AM654 timer is compatible with the omap-timer implementation, so
add it to the id list

Signed-off-by: Sjoerd Simons 
Reviewed-by: Tom Rini 
---

(no changes since v1)

 drivers/timer/omap-timer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/timer/omap-timer.c b/drivers/timer/omap-timer.c
index aa2e4360c1b..9b6d97dae67 100644
--- a/drivers/timer/omap-timer.c
+++ b/drivers/timer/omap-timer.c
@@ -114,6 +114,7 @@ static const struct udevice_id omap_timer_ids[] = {
{ .compatible = "ti,am335x-timer" },
{ .compatible = "ti,am4372-timer" },
{ .compatible = "ti,omap5430-timer" },
+   { .compatible = "ti,am654-timer" },
{}
 };
 
-- 
2.40.0



[PATCH v2 0/8] Add DFU, emmc and usb boot for TI am62x

2023-04-06 Thread Sjoerd Simons


This series adds more boot sources for the TI am62x. For that the dts'
are synced from the upstream ti-next git tree (to add usb nodes), some
dwc3 glue is and finally the default configuration is tuned to add
support for DFU and USB (host and gadget)


Changes in v2:
- Update dts sync to v6.3-rc5
- Switch dwc3 glue to a seperate driver rather then in dwc-generic
- Minimize config changes to just DFU configuration
- Only enable usb port 0 DFU in SPL
- Create a seperate defconfig for R5

Sjoerd Simons (8):
  omap: timer: add ti,am654-timer compatibility
  arm: mach-k3: am62: Add timer0 id to the dev list
  arm: dts: k3-am62: Bump dtsi from linux
  arm: dts: k3-am625-sk: Enable emmc in SPL
  usb: dwc3: Add dwc3 glue driver for am62
  configs: am62: Add configs for enabling USB in U-Boot
  arm: dts: k3-am625-sk: Enable usb ports in u-boot
  configs: am62x_evm_*: Enable USB and DFU support

 arch/arm/dts/k3-am62-main.dtsi| 259 +++---
 arch/arm/dts/k3-am62-mcu.dtsi |  49 +
 arch/arm/dts/k3-am62-wakeup.dtsi  |   4 +-
 arch/arm/dts/k3-am625-r5-sk.dts   |   2 +-
 arch/arm/dts/k3-am625-sk-u-boot.dtsi  |  27 ++-
 arch/arm/dts/k3-am625-sk.dts  |  95 +-
 arch/arm/dts/k3-am625.dtsi|  52 ++
 arch/arm/mach-k3/am62x/dev-data.c |   1 +
 configs/am62x_evm_a53_defconfig   |  35 +++-
 configs/am62x_evm_r5_usbdfu_defconfig | 116 
 drivers/timer/omap-timer.c|   1 +
 drivers/usb/dwc3/Kconfig  |  14 ++
 drivers/usb/dwc3/Makefile |   1 +
 drivers/usb/dwc3/dwc3-am62.c  | 127 +
 include/configs/am62x_evm.h   |  10 +-
 15 files changed, 701 insertions(+), 92 deletions(-)
 create mode 100644 configs/am62x_evm_r5_usbdfu_defconfig
 create mode 100644 drivers/usb/dwc3/dwc3-am62.c

-- 
2.40.0



Re: [PATCH 1/2] rockchip: rng: add trngv1 for rk3588

2023-04-06 Thread Heinrich Schuchardt



Am 6. April 2023 18:17:35 MESZ schrieb Chris Morgan :
>From: Chris Morgan 
>
>This adds support for the TRNG found in the RK3588 SoC to the
>rockchip_rng driver so that it can be used for things such as
>seeding randomness to Linux.
>
>This code was taken wholesale from the Rockchip BSP U-Boot source
>located here:
>https://github.com/rockchip-linux/u-boot/commit/09f31aed858c36a8a5ee20789712e65bb4762068
>
>Tested on an Indiedroid Nova with an RK3588s.
>
>Signed-off-by: Lin Jinhan 
>Signed-off-by: Chris Morgan 

Without Makefile and Kconfig changes we cannot even test if this builds.

Best regards

Heinrich


>---
> drivers/rng/rockchip_rng.c | 120 ++---
> 1 file changed, 111 insertions(+), 9 deletions(-)
>
>diff --git a/drivers/rng/rockchip_rng.c b/drivers/rng/rockchip_rng.c
>index 800150f114..705b424cf3 100644
>--- a/drivers/rng/rockchip_rng.c
>+++ b/drivers/rng/rockchip_rng.c
>@@ -43,9 +43,41 @@
> #define CRYPTO_V2_RNG_DOUT_0  0x0410
> /* end of CRYPTO V2 register define */
> 
>+/* start of TRNG V1 register define */
>+#define TRNG_V1_CTRL  0x
>+#define TRNG_V1_CTRL_NOP  _SBF(0, 0x00)
>+#define TRNG_V1_CTRL_RAND _SBF(0, 0x01)
>+#define TRNG_V1_CTRL_SEED _SBF(0, 0x02)
>+
>+#define TRNG_V1_MODE  0x0008
>+#define TRNG_V1_MODE_128_BIT  _SBF(3, 0x00)
>+#define TRNG_V1_MODE_256_BIT  _SBF(3, 0x01)
>+
>+#define TRNG_V1_IE0x0010
>+#define TRNG_V1_IE_GLBL_ENBIT(31)
>+#define TRNG_V1_IE_SEED_DONE_EN   BIT(1)
>+#define TRNG_V1_IE_RAND_RDY_ENBIT(0)
>+
>+#define TRNG_V1_ISTAT 0x0014
>+#define TRNG_V1_ISTAT_RAND_RDYBIT(0)
>+
>+/* RAND0 ~ RAND7 */
>+#define TRNG_V1_RAND0 0x0020
>+#define TRNG_V1_RAND7 0x003C
>+
>+#define TRNG_V1_AUTO_RQSTS0x0060
>+
>+#define TRNG_V1_VERSION   0x00F0
>+#define TRNG_v1_VERSION_CODE  0x46BC
>+/* end of TRNG V1 register define */
>+
> #define RK_RNG_TIME_OUT   5  /* max 50ms */
> 
>+#define trng_write(pdata, pos, val)   writel(val, (pdata)->base + (pos))
>+#define trng_read(pdata, pos) readl((pdata)->base + (pos))
>+
> struct rk_rng_soc_data {
>+  int (*rk_rng_init)(struct udevice *dev);
>   int (*rk_rng_read)(struct udevice *dev, void *data, size_t len);
> };
> 
>@@ -75,7 +107,7 @@ static int rk_rng_read_regs(fdt_addr_t addr, void *buf, 
>size_t size)
>   return 0;
> }
> 
>-static int rk_v1_rng_read(struct udevice *dev, void *data, size_t len)
>+static int rk_cryptov1_rng_read(struct udevice *dev, void *data, size_t len)
> {
>   struct rk_rng_plat *pdata = dev_get_priv(dev);
>   u32 reg = 0;
>@@ -106,7 +138,7 @@ exit:
>   return 0;
> }
> 
>-static int rk_v2_rng_read(struct udevice *dev, void *data, size_t len)
>+static int rk_cryptov2_rng_read(struct udevice *dev, void *data, size_t len)
> {
>   struct rk_rng_plat *pdata = dev_get_priv(dev);
>   u32 reg = 0;
>@@ -140,6 +172,63 @@ exit:
>   return retval;
> }
> 
>+static int rk_trngv1_init(struct udevice *dev)
>+{
>+  u32 status, version;
>+  u32 auto_reseed_cnt = 1000;
>+  struct rk_rng_plat *pdata = dev_get_priv(dev);
>+
>+  version = trng_read(pdata, TRNG_V1_VERSION);
>+  if (version != TRNG_v1_VERSION_CODE) {
>+  printf("wrong trng version, expected = %08x, actual = %08x",
>+ TRNG_V1_VERSION, version);
>+  return -EFAULT;
>+  }
>+
>+  /* wait in case of RND_RDY triggered at firs power on */
>+  readl_poll_timeout(pdata->base + TRNG_V1_ISTAT, status,
>+ (status & TRNG_V1_ISTAT_RAND_RDY),
>+ RK_RNG_TIME_OUT);
>+
>+  /* clear RAND_RDY flag for first power on */
>+  trng_write(pdata, TRNG_V1_ISTAT, status);
>+
>+  /* auto reseed after (auto_reseed_cnt * 16) byte rand generate */
>+  trng_write(pdata, TRNG_V1_AUTO_RQSTS, auto_reseed_cnt);
>+
>+  return 0;
>+}
>+
>+static int rk_trngv1_rng_read(struct udevice *dev, void *data, size_t len)
>+{
>+  struct rk_rng_plat *pdata = dev_get_priv(dev);
>+  u32 reg = 0;
>+  int retval;
>+
>+  if (len > RK_HW_RNG_MAX)
>+  return -EINVAL;
>+
>+  trng_write(pdata, TRNG_V1_MODE, TRNG_V1_MODE_256_BIT);
>+  trng_write(pdata, TRNG_V1_CTRL, TRNG_V1_CTRL_RAND);
>+
>+  retval = readl_poll_timeout(pdata->base + TRNG_V1_ISTAT, reg,
>+  (reg & TRNG_V1_ISTAT_RAND_RDY),
>+  RK_RNG_TIME_OUT);
>+  /* clear ISTAT */
>+  trng_write(pdata, TRNG_V1_ISTAT, reg);
>+
>+  if (retval)
>+  goto exit;
>+
>+  rk_rng_read_regs(pdata->base + TRNG_V1_RAND0, data, len);
>+
>+

[PATCH v3] doc: ti: Add switch setting for boot modes on AM62 SK

2023-04-06 Thread Judith Mendez
List some common boot modes and their corresponding switch
settings for AM62 SK.

List in a ASCII-style table.

Signed-off-by: Judith Mendez 
---

Changes from v1: Change table format from ascii-art to list-table
Changes from v2: Change table format to ASCII style

 doc/board/ti/am62x_sk.rst | 29 +
 1 file changed, 29 insertions(+)

diff --git a/doc/board/ti/am62x_sk.rst b/doc/board/ti/am62x_sk.rst
index b1b7d99befb..7adbdac7ca9 100644
--- a/doc/board/ti/am62x_sk.rst
+++ b/doc/board/ti/am62x_sk.rst
@@ -229,3 +229,32 @@ Image formats:
 | |   SPL DTB 1...N   | |
 | +---+ |
 +---+
+
+Switch Setting for Boot Mode
+
+
+Boot Mode pins provide means to select the boot mode and options before the
+device is powered up. After every POR, they are the main source to populate
+the Boot Parameter Tables.
+
+The following table shows some common boot modes used on AM62 platform. More
+details can be found in the Technical Reference Manual:
+https://www.ti.com/lit/pdf/spruiv7 under the `Boot Mode Pins` section.
+
+*Boot Modes*
+
+++-+-+
+|  Switch Label  |  SW2: 12345678  |  SW3: 12345678  |
+++=+=+
+| SD |  0100   |  1110   |
+++-+-+
+| OSPI   |     |  11001110   |
+++-+-+
+| EMMC   |     |  11010010   |
+++-+-+
+| UART   |     |  11011100   |
+++-+-+
+| USB DFU|     |  11001010   |
+++-+-+
+
+For SW2 and SW1, the switch state in the "ON" position = 1.
-- 
2.17.1



Re: [PATCH] doc: ti: Add switch setting for boot modes on AM62 SK

2023-04-06 Thread Mendez, Judith

Hello,

On 4/4/2023 9:22 AM, Tom Rini wrote:

On Tue, Apr 04, 2023 at 03:59:56PM +0200, Heinrich Schuchardt wrote:

On 3/31/23 22:36, Judith Mendez wrote:

List some common boot modes and their corresponding switch
settings for AM62 SK.

Signed-off-by: Judith Mendez 
---

Changes from v1: Change table format from ascii-art to list-table

   doc/board/ti/am62x_sk.rst | 36 
   1 file changed, 36 insertions(+)

diff --git a/doc/board/ti/am62x_sk.rst b/doc/board/ti/am62x_sk.rst
index b1b7d99befb..3d85400b1a1 100644
--- a/doc/board/ti/am62x_sk.rst
+++ b/doc/board/ti/am62x_sk.rst
@@ -229,3 +229,39 @@ Image formats:
   | |   SPL DTB 1...N   | |
   | +---+ |
   +---+
+
+Switch Setting for Boot Mode
+
+
+Boot Mode pins provide means to select the boot mode and options before the
+device is powered up. After every POR, they are the main source to populate
+the Boot Parameter Tables.
+
+The following table shows some common boot modes used on AM62 platform. More
+details can be found in the Technical Reference Manual:
+https://www.ti.com/lit/pdf/spruiv7 under the `Boot Mode Pins` section.
+
+.. list-table:: Boot Modes
+   :widths: 32 32 32
+   :header-rows: 1
+
+   * - Switch Label
+ - SW2: 12345678
+ - SW3: 12345678
+   * - SD
+ - 0100
+ - 1110
+   * - OSPI
+ - 
+ - 11001110
+   * - EMMC
+ - 
+ - 11010010
+   * - UART
+ - 
+ - 11011100
+   * - USB DFU
+ - 
+ - 11001010


Hello Judith,

ReStructured text allows different flavors of formatting tables.

The HTML output for the table above is correct but the .rst file is hard
to read in a text-editor. I would prefer:

*Boot Modes*

 = =
Switch Label SW2: 12345678 SW3: 12345678
 = =
SD   0100  1110
OSPI   11001110
EMMC   11010010
UART   11011100
USB DFU    11001010
 = =


There's other list-table entires in the docs today. I'm fine either way,
but we need to be consistent in the docs, and should update perhaps
doc/develop/codingstyle.rst should get a section too on docs?



I will send again with the ASCII-style so y'all have the option.

regards,
Judith


[PATCH v1 9/9] DONOTMERGE: arm: dts: k3-am62a7-sk: Add TI TPS6593 PMIC support

2023-04-06 Thread Jerome Neanne
Add support for TPS6593 PMIC devices:
- regulators (bucks and LDOs) on main I2C0 bus,
- watchdog on MCU I2C0 bus.

Signed-off-by: Julien Panis 
Signed-off-by: Jerome Neanne 
---
 arch/arm/dts/k3-am62a7-sk-u-boot.dtsi | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/k3-am62a7-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am62a7-sk-u-boot.dtsi
index 7fc749ed70..4b2e9f7d22 100644
--- a/arch/arm/dts/k3-am62a7-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am62a7-sk-u-boot.dtsi
@@ -84,7 +84,14 @@
 };
 
 &mcu_pmx0 {
-   u-boot,dm-spl;
+   status = "okay";
+
+   mcu_i2c0_pins_default: mcu_i2c0_pins_default {
+   pinctrl-single,pins = <
+   AM62X_MCU_IOPAD(0x044, PIN_INPUT_PULLUP, 0) /* (E12) 
MCU_I2C0_SCL */
+   AM62X_MCU_IOPAD(0x048, PIN_INPUT_PULLUP, 0) /* (D9) 
MCU_I2C0_SDA */
+   >;
+   };
 };
 
 &wkup_uart0 {
@@ -96,7 +103,20 @@
 };
 
 &main_i2c0 {
-   u-boot,dm-spl;
+   tps659312: tps659312@48 {
+   compatible = "ti,tps659312";
+   };
+};
+
+&mcu_i2c0 {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <&mcu_i2c0_pins_default>;
+
+   tps65931_wd: tps65931_wd@12 {
+   compatible = "ti,tps65941_watchdog";
+   reg = <0x12>;
+   };
 };
 
 &main_i2c0_pins_default {
-- 
2.25.1



[PATCH v1 8/9] configs: am62ax_evm_a53: Enable support for TI TPS6593 PMIC

2023-04-06 Thread Jerome Neanne
From: Julien Panis 

Add support for TPS6593 regulators and watchdog.
PMIC is controlled by SoC through I2C interface.

Signed-off-by: Julien Panis 
Signed-off-by: Jerome Neanne 
---
 configs/am62ax_evm_a53_defconfig | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/configs/am62ax_evm_a53_defconfig b/configs/am62ax_evm_a53_defconfig
index 8b48f5e8e6..358271204a 100644
--- a/configs/am62ax_evm_a53_defconfig
+++ b/configs/am62ax_evm_a53_defconfig
@@ -50,7 +50,6 @@ CONFIG_SPL_CLK=y
 CONFIG_CLK_TI_SCI=y
 CONFIG_TI_SCI_PROTOCOL=y
 # CONFIG_GPIO is not set
-# CONFIG_I2C is not set
 CONFIG_DM_MAILBOX=y
 CONFIG_K3_SEC_PROXY=y
 CONFIG_MMC_SDHCI=y
@@ -74,3 +73,11 @@ CONFIG_SPL_SYSRESET=y
 CONFIG_SYSRESET_TI_SCI=y
 CONFIG_FS_FAT_MAX_CLUSTSIZE=16384
 CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_TPS65941=y
+CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_TPS65941=y
+CONFIG_DM_I2C=y
+CONFIG_I2C=y
+CONFIG_SPL_I2C=y
+CONFIG_SYS_I2C_OMAP24XX=y
-- 
2.25.1



[PATCH v1 7/9] DONOTMERGE: arm: dts: k3-j721e: realign node name on linux dts name

2023-04-06 Thread Jerome Neanne
Change node name to reuse Linux common dts naming style.

Signed-off-by: Jerome Neanne 
---
 arch/arm/dts/k3-j721e-r5-common-proc-board-u-boot.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/dts/k3-j721e-r5-common-proc-board-u-boot.dtsi 
b/arch/arm/dts/k3-j721e-r5-common-proc-board-u-boot.dtsi
index 48c6ddf672..206f8560f9 100644
--- a/arch/arm/dts/k3-j721e-r5-common-proc-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-j721e-r5-common-proc-board-u-boot.dtsi
@@ -21,7 +21,7 @@
};
 };
 
-&tps659413a {
+&tps659413 {
esm: esm {
compatible = "ti,tps659413-esm";
u-boot,dm-spl;
-- 
2.25.1



[PATCH v1 6/9] DONOTMERGE: arm: dts: k3-j721e: refactor r5 board file to use Linux dts tps6594 description

2023-04-06 Thread Jerome Neanne
Use a copy of Linux dts for TPS6594 PMIC description
instead of custom u-boot

Signed-off-by: Jerome Neanne 
---
 .../arm/dts/k3-j721e-r5-common-proc-board.dts | 48 +--
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/arch/arm/dts/k3-j721e-r5-common-proc-board.dts 
b/arch/arm/dts/k3-j721e-r5-common-proc-board.dts
index ab9d6e65d8..a5c0222e91 100644
--- a/arch/arm/dts/k3-j721e-r5-common-proc-board.dts
+++ b/arch/arm/dts/k3-j721e-r5-common-proc-board.dts
@@ -21,6 +21,27 @@
tick-timer = &timer1;
};
 
+   evm_12v0: fixedregulator-evm12v0 {
+   /* main supply */
+   compatible = "regulator-fixed";
+   regulator-name = "evm_12v0";
+   regulator-min-microvolt = <1200>;
+   regulator-max-microvolt = <1200>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   vsys_3v3: fixedregulator-vsys3v3 {
+   /* Output of LM5140 */
+   compatible = "regulator-fixed";
+   regulator-name = "vsys_3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <&evm_12v0>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
a72_0: a72@0 {
compatible = "ti,am654-rproc";
reg = <0x0 0x00a9 0x0 0x10>;
@@ -276,33 +297,8 @@
ti,driver-strength-ohm = <50>;
 };
 
-&wkup_i2c0 {
-   u-boot,dm-spl;
-   tps659413a: tps659413a@48 {
-   reg = <0x48>;
-   compatible = "ti,tps659413";
-   u-boot,dm-spl;
-   pinctrl-names = "default";
-   pinctrl-0 = <&wkup_i2c0_pins_default>;
-   clock-frequency = <40>;
-
-   regulators: regulators {
-   u-boot,dm-spl;
-   buck12_reg: buck12 {
-   /*VDD_CPU*/
-   regulator-name = "buck12";
-   regulator-min-microvolt = <60>;
-   regulator-max-microvolt = <90>;
-   regulator-always-on;
-   regulator-boot-on;
-   u-boot,dm-spl;
-   };
-   };
-   };
-};
-
 &wkup_vtm0 {
-   vdd-supply-2 = <&buck12_reg>;
+   vdd-supply-2 = <&bucka12_reg>;
u-boot,dm-spl;
 };
 
-- 
2.25.1



[PATCH v1 5/9] DONOTMERGE: arm: dts: k3-j721e: u-boot overlay for TI tps6594 PMIC

2023-04-06 Thread Jerome Neanne
j721e board includes 2 instances of TPS6594:
- Primary PMIC
- Secondary PMIC

Add AVS class0 in u-boot SPL.
AVS is supported only on CPU rail: vdd_cpu_avs.
This rail is supplied by the primary PMIC: tps659413
This rail is supplied by a dual-phased buck: buck12.

Other PMICs rails are not AVS capable.

Each PMIC includes a Watchdog that is active by default at boot.
This would issue a platform reset unless pmic GPIO8 is driven
or this is handled by SW.
Watchdog driver is not required for identified use of this product.
This software disable inside u-boot avoids parasitic wd reset.
GPIO8 can then be used for other purpose.

Board documentation:
Link: https://www.ti.com/tool/J721EXSOMXEVM

Signed-off-by: Jerome Neanne 
---
 .../k3-j721e-common-proc-board-u-boot.dtsi| 21 +++
 1 file changed, 21 insertions(+)

diff --git a/arch/arm/dts/k3-j721e-common-proc-board-u-boot.dtsi 
b/arch/arm/dts/k3-j721e-common-proc-board-u-boot.dtsi
index b2b81f804d..d05d3610ff 100644
--- a/arch/arm/dts/k3-j721e-common-proc-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-j721e-common-proc-board-u-boot.dtsi
@@ -79,6 +79,14 @@
chipid@4314 {
u-boot,dm-spl;
};
+
+   mcu_i2c0: i2c@40b0 {
+   status = "okay";
+   tps65941_wd: tps65941-wd@12 {
+   compatible = "ti,tps65941_watchdog";
+   reg = <0x12>;
+   };
+   };
 };
 
 &secure_proxy_main {
@@ -170,6 +178,19 @@
 
 &wkup_i2c0 {
u-boot,dm-spl;
+   tps659413: tps659413@48 {
+   u-boot,dm-spl;
+   compatible = "ti,tps659413";
+
+   regulators {
+   u-boot,dm-spl;
+   bucka12_reg: buck12 {
+   };
+   };
+   };
+   tps659411: tps659411@4c {
+   compatible = "ti,tps659411";
+   };
 };
 
 &main_i2c0 {
-- 
2.25.1



[PATCH v1 4/9] board: ti: k3-j721e: Force TPS65941 PMIC WD disable on j721e TI EVM board

2023-04-06 Thread Jerome Neanne
Using uclass_probe_all forces probe on all devices:
Only probe for WD stop is really needed here.
Probing other devices has no impact.

Signed-off-by: Jerome Neanne 
---
 board/ti/j721e/evm.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c
index d4e672a7ac..a3304468d4 100644
--- a/board/ti/j721e/evm.c
+++ b/board/ti/j721e/evm.c
@@ -27,6 +27,8 @@
 
 #include "../common/board_detect.h"
 
+#include 
+
 #define board_is_j721e_som()   (board_ti_k3_is("J721EX-PM1-SOM") || \
 board_ti_k3_is("J721EX-PM2-SOM"))
 
@@ -43,6 +45,12 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
 {
+   int ret;
+
+   /* WD stop is applied unconditionally on all platforms*/
+   ret = uclass_probe_all(UCLASS_PMIC);
+   if (ret)
+   printf("Failed to probe! stop tps65941 wd\n");
return 0;
 }
 
-- 
2.25.1



[PATCH v1 3/9] configs: j721e_evm: Add support for TPS65941 PMICs on j721e TI EVM board

2023-04-06 Thread Jerome Neanne
Add PMIC and regulators feature support for j721e.
PMIC is controlled by SoC through I2C interface.

Signed-off-by: Jerome Neanne 
---
 configs/j721e_evm_a72_defconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/configs/j721e_evm_a72_defconfig b/configs/j721e_evm_a72_defconfig
index 452e4b9695..7774330b60 100644
--- a/configs/j721e_evm_a72_defconfig
+++ b/configs/j721e_evm_a72_defconfig
@@ -77,6 +77,8 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TIME=y
+CONFIG_CMD_PMIC=y
+CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_MTDIDS_DEFAULT="nor0=4704.spi.0,nor0=47034000.hyperbus"
 
CONFIG_MTDPARTS_DEFAULT="mtdparts=4704.spi.0:512k(ospi.tiboot3),2m(ospi.tispl),4m(ospi.u-boot),256k(ospi.env),1m(ospi.sysfw),256k(ospi.env.backup),57344k@8m(ospi.rootfs),256k(ospi.phypattern);47034000.hyperbus:512k(hbmc.tiboot3),2m(hbmc.tispl),4m(hbmc.u-boot),256k(hbmc.env),1m(hbmc.sysfw),-@8m(hbmc.rootfs)"
@@ -205,3 +207,10 @@ CONFIG_UFS=y
 CONFIG_CADENCE_UFS=y
 CONFIG_TI_J721E_UFS=y
 CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_DM_PMIC=y
+CONFIG_PMIC_TPS65941=y
+CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_TPS65941=y
+CONFIG_CMD_DM=y
+CONFIG_OF_PLATDATA=y
+
-- 
2.25.1



[PATCH v1 2/9] drivers: regulator: Fixes for TPS65941 LDO voltage conversion

2023-04-06 Thread Jerome Neanne
Fixes: 065a452ae6a power: regulator: tps65941: add regulator support

LDO voltage conversion was incorrect.
This was checked by writing and reading back value.

Signed-off-by: Jerome Neanne 
---
 drivers/power/regulator/tps65941_regulator.c | 71 +---
 1 file changed, 63 insertions(+), 8 deletions(-)

diff --git a/drivers/power/regulator/tps65941_regulator.c 
b/drivers/power/regulator/tps65941_regulator.c
index b041126775..7afd68c5c4 100644
--- a/drivers/power/regulator/tps65941_regulator.c
+++ b/drivers/power/regulator/tps65941_regulator.c
@@ -212,12 +212,55 @@ static int tps65941_ldo_enable(struct udevice *dev, int 
op, bool *enable)
return 0;
 }
 
-static int tps65941_ldo_val2volt(int val)
+static int tps65941_ldo_volt2val(int idx, int uV)
 {
-   if (val > TPS65941_LDO_VOLT_MAX_HEX || val < TPS65941_LDO_VOLT_MIN_HEX)
+   int base = TPS65941_LDO123_VOLT_MIN;
+   int max = TPS65941_LDO_VOLT_MAX;
+   int offset = TPS65941_LDO123_VSET_MIN;
+   int step = TPS65941_LDO123_STEP;
+
+   if (idx > 2) {
+   base = TPS65941_LDO4_VOLT_MIN;
+   offset = TPS65941_LDO4_VSET_MIN;
+   step = TPS65941_LDO4_STEP;
+   }
+
+   if (uV > max)
return -EINVAL;
-   else if (val >= TPS65941_LDO_VOLT_MIN_HEX)
-   return 60 + (val - TPS65941_LDO_VOLT_MIN_HEX) * 5;
+   else if (uV >= base)
+   return (uV - base) / step + offset;
+   else
+   return -EINVAL;
+}
+
+static int tps65941_ldo_val2volt(int idx, int val)
+{
+   int reg_base = TPS65941_LDO123_VSET_MIN;
+   int reg_max = TPS65941_LDO123_VSET_MAX;
+   int base = TPS65941_LDO123_VOLT_MIN;
+   int max = TPS65941_LDO_VOLT_MAX;
+   int step = TPS65941_LDO123_STEP;
+   int mask = TPS65941_LDO_VOLT_MASK >> 1;
+
+   if (idx > 2) {
+   base = TPS65941_LDO4_VOLT_MIN;
+   max = TPS65941_LDO_VOLT_MAX;
+   reg_base = TPS65941_LDO4_VSET_MIN;
+   reg_max = TPS65941_LDO4_VSET_MAX;
+   step = TPS65941_LDO4_STEP;
+   mask = TPS65941_LDO_VOLT_MASK;
+   } else {
+   val = val >> 1;
+   }
+
+   if (val > mask || val < 0)
+   return -EINVAL;
+   else if (val >= reg_max)
+   return max;
+   else if (val <= reg_base)
+   return base;
+   else if (val >= 0)
+   return base + (step * (val - reg_base));
else
return -EINVAL;
 }
@@ -227,7 +270,9 @@ static int tps65941_ldo_val(struct udevice *dev, int op, 
int *uV)
unsigned int hex, adr;
int ret;
struct dm_regulator_uclass_plat *uc_pdata;
+   int idx;
 
+   idx = dev->driver_data - 1;
uc_pdata = dev_get_uclass_plat(dev);
 
if (op == PMIC_OP_GET)
@@ -240,7 +285,8 @@ static int tps65941_ldo_val(struct udevice *dev, int op, 
int *uV)
return ret;
 
ret &= TPS65941_LDO_VOLT_MASK;
-   ret = tps65941_ldo_val2volt(ret);
+   ret = tps65941_ldo_val2volt(idx, ret);
+
if (ret < 0)
return ret;
 
@@ -249,12 +295,21 @@ static int tps65941_ldo_val(struct udevice *dev, int op, 
int *uV)
return 0;
}
 
-   hex = tps65941_buck_volt2val(*uV);
+   /* LDO1, LDO2 & LDO3 in BYPASS mode only supports 1.7V min to 3.6V max 
*/
+   if (idx < 2 &&
+   (ret & BIT(TPS65941_LDO123_BYP_CONFIG)) &&
+   *uV < TPS65941_LDO123_VOLT_BYP_MIN)
+   return -EINVAL;
+
+   hex = tps65941_ldo_volt2val(idx, *uV);
if (hex < 0)
return hex;
 
-   ret &= 0x0;
-   ret = hex;
+   if (idx < 2)
+   hex = hex << 1;
+
+   ret &= ~TPS65941_LDO_VOLT_MASK;
+   ret |= hex;
 
ret = pmic_reg_write(dev->parent, adr, ret);
 
-- 
2.25.1



[PATCH v1 1/9] drivers: pmic: TPS65941 add support for WD disable

2023-04-06 Thread Jerome Neanne
This is not a proper WD driver because it's not planned to
support WD driver for PMIC in u-boot at any time.
The purpose is just WD disable.

Signed-off-by: Jerome Neanne 
---
 drivers/power/pmic/tps65941.c | 36 +++
 include/power/tps65941.h  | 25 ++--
 2 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/drivers/power/pmic/tps65941.c b/drivers/power/pmic/tps65941.c
index 83d0f83c64..643ea6179c 100644
--- a/drivers/power/pmic/tps65941.c
+++ b/drivers/power/pmic/tps65941.c
@@ -47,6 +47,9 @@ static int tps65941_bind(struct udevice *dev)
ofnode regulators_node;
int children;
 
+   if (dev->driver_data == TPS65941_WD)
+   return 0;
+
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
debug("%s: %s regulators subnode not found!\n", __func__,
@@ -64,6 +67,36 @@ static int tps65941_bind(struct udevice *dev)
return dm_scan_fdt_dev(dev);
 }
 
+static int stop_watchdog(struct udevice *wd_i2c_dev)
+{
+   int ret;
+
+   ret = dm_i2c_reg_read(wd_i2c_dev, TPS65941_WD_MODE_REG);
+   if (ret < 0) {
+   debug("failed to write i2c reg (%d)\n", ret);
+   return 0;
+   }
+
+   ret &= ~TPS65941_WD_PWRHOLD_MASK;
+   ret |= TPS65941_WD_PWRHOLD_MASK;
+   ret = dm_i2c_reg_write(wd_i2c_dev, TPS65941_WD_MODE_REG, ret);
+   if (ret)
+   debug("%s: %s write WD disable fail!\n", __func__, 
wd_i2c_dev->name);
+   ret = dm_i2c_reg_read(wd_i2c_dev, TPS65941_WD_MODE_REG);
+   if (ret < 0) {
+   debug("failed to read back i2c reg (%d)\n", ret);
+   return 0;
+   }
+   return 0;
+}
+
+static int tps65941_probe(struct udevice *dev)
+{
+   if (dev->driver_data == TPS65941_WD)
+   return stop_watchdog(dev);
+   return 0;
+}
+
 static struct dm_pmic_ops tps65941_ops = {
.read = tps65941_read,
.write = tps65941_write,
@@ -73,7 +106,9 @@ static const struct udevice_id tps65941_ids[] = {
{ .compatible = "ti,tps659411", .data = TPS659411 },
{ .compatible = "ti,tps659412", .data = TPS659411 },
{ .compatible = "ti,tps659413", .data = TPS659413 },
+   { .compatible = "ti,tps659312", .data = TPS659312 },
{ .compatible = "ti,lp876441",  .data =  LP876441 },
+   { .compatible = "ti,tps65941_watchdog",  .data =  TPS65941_WD },
{ }
 };
 
@@ -82,5 +117,6 @@ U_BOOT_DRIVER(pmic_tps65941) = {
.id = UCLASS_PMIC,
.of_match = tps65941_ids,
.bind = tps65941_bind,
+   .probe = tps65941_probe,
.ops = &tps65941_ops,
 };
diff --git a/include/power/tps65941.h b/include/power/tps65941.h
index a2bc6814ba..70c7274355 100644
--- a/include/power/tps65941.h
+++ b/include/power/tps65941.h
@@ -2,7 +2,9 @@
 #define TPS659412  0x1
 #define TPS659413  0x2
 #define TPS659414  0x3
-#define  LP876441  0x4
+#define TPS659312  0x4
+#define LP876441   0x5
+#define TPS65941_WD0x20
 
 /* I2C device address for pmic tps65941 */
 #define TPS65941_I2C_ADDR  (0x12 >> 1)
@@ -18,10 +20,29 @@
 #define TPS65941_BUCK_VOLT_MAX 334
 #define TPS65941_BUCK_MODE_MASK0x1
 
-#define TPS65941_LDO_VOLT_MASK 0x3E
+#define TPS65941_LDO_VOLT_MASK 0x7F
 #define TPS65941_LDO_VOLT_MAX_HEX  0x3A
 #define TPS65941_LDO_VOLT_MIN_HEX  0x4
 #define TPS65941_LDO_VOLT_MAX  330
 #define TPS65941_LDO_MODE_MASK 0x1
 #define TPS65941_LDO_BYPASS_EN 0x80
 #define TP65941_BUCK_CONF_SLEW_MASK0x7
+
+/* BYPASS is bit7 of VOUT TPS65941_LDO_BYP_MASK */
+#define TPS65941_LDO123_BYP_CONFIG   7
+
+#define TPS65941_LDO123_VOLT_BYP_MIN   170
+#define TPS65941_LDO123_VOLT_BYP_MAX   360
+#define TPS65941_LDO123_VOLT_MIN   60
+#define TPS65941_LDO4_VOLT_MIN 120
+#define TPS65941_LDO4_VOLT_MIN 120
+#define TPS65941_LDO123_VSET_MIN   0x04
+#define TPS65941_LDO4_VSET_MIN 0x20
+#define TPS65941_LDO123_VSET_MAX   0x3A
+#define TPS65941_LDO4_VSET_MAX 0x74
+#define TPS65941_LDO123_STEP   5
+#define TPS65941_LDO4_STEP 25000
+
+#define TPS65941_WD_MODE_REG   0x406
+#define TPS65941_WD_PWRHOLD_MASK   BIT(2)
+
-- 
2.25.1



[PATCH v1 0/9] TI TPS6594 PMIC support for multiple TI EVMs

2023-04-06 Thread Jerome Neanne
TPS6594 is a Power Management IC which provides regulators and others
features like GPIOs, RTC, watchdog, ESMs (Error Signal Monitor), and
PFSM (Pre-configurable Finite State Machine). The SoC and the PMIC can
communicate through the I2C or SPI interfaces.
TPS6594 is the super-set device while TPS6593 and LP8764X are derivatives.

This series fixes LDO voltage conversion for TPS6594 PMIC,
it adds support for its derivatives.

The features implemented are:
- Regulators
- WD disable

WD disable is not a watchdog driver implementation.
Watchdog is active by default causing a reboot even if not used.
This implementation allow to disable the watchdog at boot time.

Due to current situation with upstream u-boot dts,
this patch suite can be applied only after u-boot dts upstream is
resynched on latest Linux dts.
Link: https://gist.github.com/nmenon/030b11b085473fa008145429b39fcc75

This should be applied on top of Linux patch series (for dts inheritence)
Link: https://lore.kernel.org/all/20230406075622.8990-1-jpa...@baylibre.com/
Link: https://lore.kernel.org/all/20230328091448.648452-1-ebl...@baylibre.com/

Tested on boards listed below (resynched manually on Linux 6.3 dts)

Supported boards:
- j721eXSOMXEVM:
Link: https://www.ti.com/tool/J721EXSOMXEVM
- AM62A-SKEVM:
Link: https://www.ti.com/tool/SK-AM62A-LP

basic tests:
=> pmic list
=> regulator list
=> regulator dev reg_name_to_be_tested
=> regulator info
=> regulator value
=> regulator value my_test_val
=> regulator value
Check WD reset is not happening when dip switch SW2 on GPIO8 is High.

Jerome Neanne (4):
  drivers: pmic: TPS65941 add support for WD disable
  drivers: regulator: Fixes for TPS65941 LDO voltage conversion
  configs: j721e_evm: Add support for TPS65941 PMICs on j721e TI EVM
board
  board: ti: k3-j721e: Force TPS65941 PMIC WD disable on j721e TI EVM
board

Jerome Neanne (4):
  DONOTMERGE: arm: dts: k3-j721e: u-boot overlay for TI tps6594 PMIC
  DONOTMERGE: arm: dts: k3-j721e: refactor r5 board file to use Linux
dts tps6594 description
  DONOTMERGE: arm: dts: k3-j721e: realign node name on linux dts name
  DONOTMERGE: arm: dts: k3-am62a7-sk: Add TI TPS6593 PMIC support

Julien Panis (1):
  configs: am62ax_evm_a53: Enable support for TI TPS6593 PMIC

 arch/arm/dts/k3-am62a7-sk-u-boot.dtsi | 24 ++-
 .../k3-j721e-common-proc-board-u-boot.dtsi| 21 ++
 .../k3-j721e-r5-common-proc-board-u-boot.dtsi |  2 +-
 .../arm/dts/k3-j721e-r5-common-proc-board.dts | 48 ++---
 board/ti/j721e/evm.c  |  8 +++
 configs/am62ax_evm_a53_defconfig  |  9 ++-
 configs/j721e_evm_a72_defconfig   |  9 +++
 drivers/power/pmic/tps65941.c | 36 ++
 drivers/power/regulator/tps65941_regulator.c  | 71 ---
 include/power/tps65941.h  | 25 ++-
 10 files changed, 213 insertions(+), 40 deletions(-)

-- 
2.25.1



[PATCH v4 12/12] arm: mach-k3: Remove empty sys_proto.h include

2023-04-06 Thread Andrew Davis
This header file is now empty, remove it.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/am642_init.c |  2 --
 arch/arm/mach-k3/am654_init.c |  1 -
 arch/arm/mach-k3/common.c |  1 -
 arch/arm/mach-k3/include/mach/sys_proto.h | 10 --
 arch/arm/mach-k3/j721e_init.c |  1 -
 arch/arm/mach-k3/j721s2_init.c|  1 -
 arch/arm/mach-k3/security.c   |  1 -
 arch/arm/mach-k3/sysfw-loader.c   |  1 -
 board/siemens/iot2050/board.c |  1 -
 board/ti/am62ax/evm.c |  1 -
 board/ti/am62x/evm.c  |  1 -
 board/ti/am64x/evm.c  |  1 -
 board/ti/am65x/evm.c  |  2 --
 board/ti/j721e/evm.c  |  2 --
 board/ti/j721s2/evm.c |  2 --
 drivers/phy/phy-ti-am654.c|  1 -
 drivers/ram/k3-am654-ddrss.c  |  1 -
 17 files changed, 30 deletions(-)
 delete mode 100644 arch/arm/mach-k3/include/mach/sys_proto.h

diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index ef84aad819c..5d53358cf26 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -13,9 +13,7 @@
 #include 
 #include 
 #include "sysfw-loader.h"
-#include 
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
index 2336da4b454..0d3889cde2b 100644
--- a/arch/arm/mach-k3/am654_init.c
+++ b/arch/arm/mach-k3/am654_init.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include "sysfw-loader.h"
-#include 
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 9f2f5a98771..e29e51b7042 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
deleted file mode 100644
index 5638c6f8c8a..000
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
- * Andreas Dannenberg 
- */
-
-#ifndef _SYS_PROTO_H_
-#define _SYS_PROTO_H_
-
-#endif
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 31d324e2179..9bba5f79545 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -14,7 +14,6 @@
 #include 
 #include "sysfw-loader.h"
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
index 175ac4028a0..001d9466c20 100644
--- a/arch/arm/mach-k3/j721s2_init.c
+++ b/arch/arm/mach-k3/j721s2_init.c
@@ -14,7 +14,6 @@
 #include 
 #include "sysfw-loader.h"
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/security.c b/arch/arm/mach-k3/security.c
index 092588f4b5e..6179f7373aa 100644
--- a/arch/arm/mach-k3/security.c
+++ b/arch/arm/mach-k3/security.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "common.h"
diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
index c4c5c371100..9be2d9eaea2 100644
--- a/arch/arm/mach-k3/sysfw-loader.c
+++ b/arch/arm/mach-k3/sysfw-loader.c
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 #include "common.h"
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/board/siemens/iot2050/board.c b/board/siemens/iot2050/board.c
index 1ba3e90c6fc..2653e107450 100644
--- a/board/siemens/iot2050/board.c
+++ b/board/siemens/iot2050/board.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/am62ax/evm.c b/board/ti/am62ax/evm.c
index beef3f2f3da..f2dd3b4192e 100644
--- a/board/ti/am62ax/evm.c
+++ b/board/ti/am62ax/evm.c
@@ -7,7 +7,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/am62x/evm.c b/board/ti/am62x/evm.c
index 20b2a701223..034fbed3aa4 100644
--- a/board/ti/am62x/evm.c
+++ b/board/ti/am62x/evm.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/board/ti/am64x/evm.c b/board/ti/am64x/evm.c
index c88139ac7ac..b63792e 100644
--- a/board/ti/am64x/evm.c
+++ b/board/ti/am64x/evm.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "../common/board_detect.h"
diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index 4053b8333cf..706b2198183 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -13,7 +13,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -21,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "../common/board_detect.h"
 
diff --git a/board/ti/j721e/evm.c

[PATCH v4 11/12] arm: mach-k3: Move J721s2 SPL init functions to mach-k3

2023-04-06 Thread Andrew Davis
This matches AM64 and J721e and removes the need to forward
declare k3_spl_init(), k3_mem_init(), and check_rom_loaded_sysfw()
in sys_proto.h.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/include/mach/sys_proto.h |  3 --
 arch/arm/mach-k3/j721s2_init.c| 64 +++
 board/ti/j721s2/evm.c | 63 --
 3 files changed, 64 insertions(+), 66 deletions(-)

diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 4b4e2a5be39..5638c6f8c8a 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -7,7 +7,4 @@
 #ifndef _SYS_PROTO_H_
 #define _SYS_PROTO_H_
 
-void k3_spl_init(void);
-void k3_mem_init(void);
-bool check_rom_loaded_sysfw(void);
 #endif
diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
index 4785a747bf3..175ac4028a0 100644
--- a/arch/arm/mach-k3/j721s2_init.c
+++ b/arch/arm/mach-k3/j721s2_init.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -182,6 +183,69 @@ void k3_mem_init(void)
spl_enable_dcache();
 }
 
+/* Support for the various EVM / SK families */
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+void do_dt_magic(void)
+{
+   int ret, rescan, mmc_dev = -1;
+   static struct mmc *mmc;
+
+   do_board_detect();
+
+   /*
+* Board detection has been done.
+* Let us see if another dtb wouldn't be a better match
+* for our board
+*/
+   if (IS_ENABLED(CONFIG_CPU_V7R)) {
+   ret = fdtdec_resetup(&rescan);
+   if (!ret && rescan) {
+   dm_uninit();
+   dm_init_and_scan(true);
+   }
+   }
+
+   /*
+* Because of multi DTB configuration, the MMC device has
+* to be re-initialized after reconfiguring FDT inorder to
+* boot from MMC. Do this when boot mode is MMC and ROM has
+* not loaded SYSFW.
+*/
+   switch (spl_boot_device()) {
+   case BOOT_DEVICE_MMC1:
+   mmc_dev = 0;
+   break;
+   case BOOT_DEVICE_MMC2:
+   case BOOT_DEVICE_MMC2_2:
+   mmc_dev = 1;
+   break;
+   }
+
+   if (mmc_dev > 0 && !check_rom_loaded_sysfw()) {
+   ret = mmc_init_device(mmc_dev);
+   if (!ret) {
+   mmc = find_mmc_device(mmc_dev);
+   if (mmc) {
+   ret = mmc_init(mmc);
+   if (ret)
+   printf("mmc init failed with error: 
%d\n", ret);
+   }
+   }
+   }
+}
+#endif
+
+#ifdef CONFIG_SPL_BUILD
+void board_init_f(ulong dummy)
+{
+   k3_spl_init();
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+   do_dt_magic();
+#endif
+   k3_mem_init();
+}
+#endif
+
 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
switch (boot_device) {
diff --git a/board/ti/j721s2/evm.c b/board/ti/j721s2/evm.c
index 9b130c141ac..d3f9a655899 100644
--- a/board/ti/j721s2/evm.c
+++ b/board/ti/j721s2/evm.c
@@ -192,66 +192,3 @@ int board_late_init(void)
 void spl_board_init(void)
 {
 }
-
-/* Support for the various EVM / SK families */
-#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
-void do_dt_magic(void)
-{
-   int ret, rescan, mmc_dev = -1;
-   static struct mmc *mmc;
-
-   do_board_detect();
-
-   /*
-* Board detection has been done.
-* Let us see if another dtb wouldn't be a better match
-* for our board
-*/
-   if (IS_ENABLED(CONFIG_CPU_V7R)) {
-   ret = fdtdec_resetup(&rescan);
-   if (!ret && rescan) {
-   dm_uninit();
-   dm_init_and_scan(true);
-   }
-   }
-
-   /*
-* Because of multi DTB configuration, the MMC device has
-* to be re-initialized after reconfiguring FDT inorder to
-* boot from MMC. Do this when boot mode is MMC and ROM has
-* not loaded SYSFW.
-*/
-   switch (spl_boot_device()) {
-   case BOOT_DEVICE_MMC1:
-   mmc_dev = 0;
-   break;
-   case BOOT_DEVICE_MMC2:
-   case BOOT_DEVICE_MMC2_2:
-   mmc_dev = 1;
-   break;
-   }
-
-   if (mmc_dev > 0 && !check_rom_loaded_sysfw()) {
-   ret = mmc_init_device(mmc_dev);
-   if (!ret) {
-   mmc = find_mmc_device(mmc_dev);
-   if (mmc) {
-   ret = mmc_init(mmc);
-   if (ret)
-   printf("mmc init failed with error: 
%d\n", ret);
-   }
-   }
-   }
-}
-#endif
-
-#

[PATCH v4 01/12] arm: mach-k3: Move MSMC fixup to SoC level

2023-04-06 Thread Andrew Davis
The MSMC fixup is something we do based on SoC, not based on the board.
So this fixup does not belong in the board files. Move this to the
mach-k3 common file so that it does not have to be done in each board
that uses these SoCs.

We use ft_system_setup() here instead of ft_board_setup() since it is no
longer board level. Enable OF_SYSTEM_SETUP in the configurations that use
this to keep functionality the same.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/common.c | 16 
 arch/arm/mach-k3/include/mach/sys_proto.h |  1 -
 board/siemens/iot2050/board.c | 11 +--
 board/ti/am65x/evm.c  | 18 --
 board/ti/j721e/evm.c  | 11 +--
 board/ti/j721s2/evm.c | 16 
 configs/am65x_evm_a53_defconfig   |  2 +-
 configs/am65x_hs_evm_a53_defconfig|  2 +-
 configs/iot2050_pg1_defconfig |  1 +
 configs/iot2050_pg2_defconfig |  1 +
 configs/j7200_evm_a72_defconfig   |  1 +
 configs/j7200_hs_evm_a72_defconfig|  1 +
 configs/j721e_evm_a72_defconfig   |  1 +
 configs/j721e_hs_evm_a72_defconfig|  1 +
 configs/j721s2_evm_a72_defconfig  |  2 +-
 configs/j721s2_hs_evm_a72_defconfig   |  2 +-
 16 files changed, 28 insertions(+), 59 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index a2adb791f6c..6870f13c520 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -386,6 +386,22 @@ int fdt_disable_node(void *blob, char *node_path)
return 0;
 }
 
+#if defined(CONFIG_OF_SYSTEM_SETUP)
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+   int ret;
+
+   ret = fdt_fixup_msmc_ram(blob, "/bus@10", "sram@7000");
+   if (ret < 0)
+   ret = fdt_fixup_msmc_ram(blob, "/interconnect@10",
+"sram@7000");
+   if (ret)
+   printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
+
+   return ret;
+}
+#endif
+
 #endif
 
 #ifndef CONFIG_SYSRESET
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 3d3d90d02d6..0b5d606eaa2 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -11,7 +11,6 @@ void sdelay(unsigned long loops);
 u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
  u32 bound);
 struct ti_sci_handle *get_ti_sci_handle(void);
-int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name);
 int do_board_detect(void);
 void release_resources_for_core_shutdown(void);
 int fdt_disable_node(void *blob, char *node_path);
diff --git a/board/siemens/iot2050/board.c b/board/siemens/iot2050/board.c
index df705b7c971..1ba3e90c6fc 100644
--- a/board/siemens/iot2050/board.c
+++ b/board/siemens/iot2050/board.c
@@ -482,19 +482,10 @@ fixup_error:
 
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
-   int ret;
-
-   ret = fdt_fixup_msmc_ram(blob, "/bus@10", "sram@7000");
-   if (ret < 0)
-   ret = fdt_fixup_msmc_ram(blob, "/interconnect@10",
-"sram@7000");
-   if (ret)
-   pr_err("%s: fixing up msmc ram failed %d\n", __func__, ret);
-
if (board_is_m2())
m2_fdt_fixup(blob);
 
-   return ret;
+   return 0;
 }
 #endif
 
diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index b266ccb4b82..4053b8333cf 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -101,24 +101,6 @@ int board_fit_config_name_match(const char *name)
 }
 #endif
 
-#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
-int ft_board_setup(void *blob, struct bd_info *bd)
-{
-   int ret;
-
-   ret = fdt_fixup_msmc_ram(blob, "/bus@10", "sram@7000");
-   if (ret < 0)
-   ret = fdt_fixup_msmc_ram(blob, "/interconnect@10",
-"sram@7000");
-   if (ret) {
-   printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
-   return ret;
-   }
-
-   return 0;
-}
-#endif
-
 #ifdef CONFIG_TI_I2C_BOARD_DETECT
 int do_board_detect(void)
 {
diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c
index d4e672a7acd..00ce009d3e8 100644
--- a/board/ti/j721e/evm.c
+++ b/board/ti/j721e/evm.c
@@ -144,18 +144,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
-   int ret;
-
-   ret = fdt_fixup_msmc_ram(blob, "/bus@10", "sram@7000");
-   if (ret < 0)
-   ret = fdt_fixup_msmc_ram(blob, "/interconnect@10",
-"sram@7000");
-   if (ret)
-   printf("%s:

[PATCH v4 07/12] arm: mach-k3: Move sysfw-loader.h out of mach includes

2023-04-06 Thread Andrew Davis
This header is only used locally by K3 init files, no need to have it
up with the global mach includes. Move into local includes.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/am625_init.c  | 2 +-
 arch/arm/mach-k3/am62a7_init.c | 2 +-
 arch/arm/mach-k3/am642_init.c  | 2 +-
 arch/arm/mach-k3/am654_init.c  | 2 +-
 arch/arm/mach-k3/j721e_init.c  | 2 +-
 arch/arm/mach-k3/j721s2_init.c | 2 +-
 arch/arm/mach-k3/{include/mach => }/sysfw-loader.h | 0
 7 files changed, 6 insertions(+), 6 deletions(-)
 rename arch/arm/mach-k3/{include/mach => }/sysfw-loader.h (100%)

diff --git a/arch/arm/mach-k3/am625_init.c b/arch/arm/mach-k3/am625_init.c
index a91c15ca4e1..026c4f9c02d 100644
--- a/arch/arm/mach-k3/am625_init.c
+++ b/arch/arm/mach-k3/am625_init.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/am62a7_init.c b/arch/arm/mach-k3/am62a7_init.c
index 02da24a3d6f..a89a9b4ae3a 100644
--- a/arch/arm/mach-k3/am62a7_init.c
+++ b/arch/arm/mach-k3/am62a7_init.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index 86aced54646..c7720cbaf35 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include 
 #include "common.h"
 #include 
diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
index abd0c0bccbc..12d74635cb0 100644
--- a/arch/arm/mach-k3/am654_init.c
+++ b/arch/arm/mach-k3/am654_init.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include 
 #include "common.h"
 #include 
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 8176ab8a499..eec5b726b95 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
index fb95984c1ab..4785a747bf3 100644
--- a/arch/arm/mach-k3/j721s2_init.c
+++ b/arch/arm/mach-k3/j721s2_init.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include "sysfw-loader.h"
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/include/mach/sysfw-loader.h 
b/arch/arm/mach-k3/sysfw-loader.h
similarity index 100%
rename from arch/arm/mach-k3/include/mach/sysfw-loader.h
rename to arch/arm/mach-k3/sysfw-loader.h
-- 
2.39.2



[PATCH v4 10/12] arm: mach-k3: Move sdelay() and wait_on_value() declaration

2023-04-06 Thread Andrew Davis
These probably should be in some system wide header given their use.
Until then move them out of K3 sys_proto.h so we can finish cleaning
that header out.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/include/mach/sys_proto.h | 4 
 drivers/ram/k3-am654-ddrss.c  | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index bbe57718e1a..4b4e2a5be39 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -7,10 +7,6 @@
 #ifndef _SYS_PROTO_H_
 #define _SYS_PROTO_H_
 
-void sdelay(unsigned long loops);
-u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
- u32 bound);
-
 void k3_spl_init(void);
 void k3_mem_init(void);
 bool check_rom_loaded_sysfw(void);
diff --git a/drivers/ram/k3-am654-ddrss.c b/drivers/ram/k3-am654-ddrss.c
index 4453c247b29..adac14f9464 100644
--- a/drivers/ram/k3-am654-ddrss.c
+++ b/drivers/ram/k3-am654-ddrss.c
@@ -18,6 +18,10 @@
 #include 
 #include "k3-am654-ddrss.h"
 
+void sdelay(unsigned long loops);
+u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
+ u32 bound);
+
 #define LDELAY 1
 
 /* DDRSS PHY configuration register fixed values */
-- 
2.39.2



[PATCH v4 08/12] arm: mach-k3: Add weak do_board_detect() to common file

2023-04-06 Thread Andrew Davis
This matches how it was done for pre-K3 TI platforms and it allows
us to move the forward declaration out of sys_proto.h.

It also removes the need for K3_BOARD_DETECT as one is free to simply
override the weak function in their board files as needed.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/Kconfig  |  5 -
 arch/arm/mach-k3/am642_init.c |  4 ++--
 arch/arm/mach-k3/am654_init.c |  4 ++--
 arch/arm/mach-k3/common.c | 10 ++
 arch/arm/mach-k3/common.h |  2 ++
 arch/arm/mach-k3/include/mach/sys_proto.h |  2 --
 arch/arm/mach-k3/j721e_init.c |  8 
 board/ti/common/Kconfig   |  1 -
 8 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 7edbac26ccc..a8c3a593d57 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -187,11 +187,6 @@ config K3_X509_SWRV
help
  SWRV for X509 certificate used for boot images
 
-config K3_BOARD_DETECT
-   bool "Support for Board detection"
-   help
-  Support for board detection.
-
 source "board/ti/am65x/Kconfig"
 source "board/ti/am64x/Kconfig"
 source "board/ti/am62x/Kconfig"
diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index c7720cbaf35..ef84aad819c 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -100,8 +100,8 @@ void do_dt_magic(void)
 {
int ret, rescan;
 
-   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
-   do_board_detect();
+   /* Perform board detection */
+   do_board_detect();
 
/*
 * Board detection has been done.
diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
index 12d74635cb0..2336da4b454 100644
--- a/arch/arm/mach-k3/am654_init.c
+++ b/arch/arm/mach-k3/am654_init.c
@@ -245,8 +245,8 @@ void board_init_f(ulong dummy)
/* Output System Firmware version info */
k3_sysfw_print_ver();
 
-   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
-   do_board_detect();
+   /* Perform board detection */
+   do_board_detect();
 
 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 4f2e14c3105..115f5959734 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -636,3 +636,13 @@ int misc_init_r(void)
 
return 0;
 }
+
+/**
+ * do_board_detect() - Detect board description
+ *
+ * Function to detect board description. This is expected to be
+ * overridden in the SoC family board file where desired.
+ */
+void __weak do_board_detect(void)
+{
+}
diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
index 531be0be54c..130f5021123 100644
--- a/arch/arm/mach-k3/common.h
+++ b/arch/arm/mach-k3/common.h
@@ -35,3 +35,5 @@ void mmr_unlock(phys_addr_t base, u32 partition);
 bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data);
 enum k3_device_type get_device_type(void);
 void ti_secure_image_post_process(void **p_image, size_t *p_size);
+struct ti_sci_handle *get_ti_sci_handle(void);
+void do_board_detect(void);
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 8cc75b636b5..939de0f79b4 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -10,8 +10,6 @@
 void sdelay(unsigned long loops);
 u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
  u32 bound);
-struct ti_sci_handle *get_ti_sci_handle(void);
-int do_board_detect(void);
 int fdt_disable_node(void *blob, char *node_path);
 
 void k3_spl_init(void);
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index eec5b726b95..31d324e2179 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -140,8 +140,8 @@ void do_dt_magic(void)
int ret, rescan, mmc_dev = -1;
static struct mmc *mmc;
 
-   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
-   do_board_detect();
+   /* Perform board detection */
+   do_board_detect();
 
/*
 * Board detection has been done.
@@ -267,8 +267,8 @@ void board_init_f(ulong dummy)
/* Output System Firmware version info */
k3_sysfw_print_ver();
 
-   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
-   do_board_detect();
+   /* Perform board detection */
+   do_board_detect();
 
 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
diff --git a/board/ti/common/Kconfig b/board/ti/common/Kconfig
index f03357cc751..49edd98014a 100644
--- a/board/ti/common/Kconfig
+++ b/board/ti/common/Kconfig
@@ -1,6 +1,5 @@
 config TI_I2C_BOARD_DETECT
bool 

[PATCH v4 09/12] arm: mach-k3: Remove unused fdt_disable_node()

2023-04-06 Thread Andrew Davis
This function is not used currently; remove it.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/common.c | 19 ---
 arch/arm/mach-k3/include/mach/sys_proto.h |  1 -
 2 files changed, 20 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 115f5959734..9f2f5a98771 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -395,25 +395,6 @@ int fdt_fixup_msmc_ram(void *blob, char *parent_path, char 
*node_name)
return 0;
 }
 
-int fdt_disable_node(void *blob, char *node_path)
-{
-   int offs;
-   int ret;
-
-   offs = fdt_path_offset(blob, node_path);
-   if (offs < 0) {
-   printf("Node %s not found.\n", node_path);
-   return offs;
-   }
-   ret = fdt_setprop_string(blob, offs, "status", "disabled");
-   if (ret < 0) {
-   printf("Could not add status property to node %s: %s\n",
-  node_path, fdt_strerror(ret));
-   return ret;
-   }
-   return 0;
-}
-
 #if defined(CONFIG_OF_SYSTEM_SETUP)
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 939de0f79b4..bbe57718e1a 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -10,7 +10,6 @@
 void sdelay(unsigned long loops);
 u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
  u32 bound);
-int fdt_disable_node(void *blob, char *node_path);
 
 void k3_spl_init(void);
 void k3_mem_init(void);
-- 
2.39.2



[PATCH v4 02/12] arm: mach-k3: Move J721e SoC detection out of common section

2023-04-06 Thread Andrew Davis
This belongs in the J721e specific file as it is the only place
this is used. Any board level users should use the SOC driver.

While here, move the J721e and J7200 SoC IDs out of sys_proto.h
and into hardware.h. Use a macro borrowed from Rockchip and add
the rest of the SoC IDs for completeness and later use.

Signed-off-by: Andrew Davis 
---
 arch/arm/mach-k3/common.c | 20 --
 arch/arm/mach-k3/common.h |  3 ---
 arch/arm/mach-k3/include/mach/hardware.h  | 25 +++
 arch/arm/mach-k3/include/mach/sys_proto.h |  3 ---
 4 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 6870f13c520..6e084de692c 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -488,26 +488,6 @@ int print_cpuinfo(void)
 }
 #endif
 
-bool soc_is_j721e(void)
-{
-   u32 soc;
-
-   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
-   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
-
-   return soc == J721E;
-}
-
-bool soc_is_j7200(void)
-{
-   u32 soc;
-
-   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
-   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
-
-   return soc == J7200;
-}
-
 #ifdef CONFIG_ARM64
 void board_prep_linux(struct bootm_headers *images)
 {
diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
index 8f38fcef7f0..531be0be54c 100644
--- a/arch/arm/mach-k3/common.h
+++ b/arch/arm/mach-k3/common.h
@@ -9,9 +9,6 @@
 #include 
 #include 
 
-#define J721E  0xbb64
-#define J7200  0xbb6d
-
 struct fwl_data {
const char *name;
u16 fwl_id;
diff --git a/arch/arm/mach-k3/include/mach/hardware.h 
b/arch/arm/mach-k3/include/mach/hardware.h
index 2c60ef85432..9faf1d6ff06 100644
--- a/arch/arm/mach-k3/include/mach/hardware.h
+++ b/arch/arm/mach-k3/include/mach/hardware.h
@@ -6,6 +6,8 @@
 #ifndef _ASM_ARCH_HARDWARE_H_
 #define _ASM_ARCH_HARDWARE_H_
 
+#include 
+
 #ifdef CONFIG_SOC_K3_AM654
 #include "am6_hardware.h"
 #endif
@@ -36,6 +38,29 @@
 #define JTAG_ID_VARIANT_MASK   (0xf << 28)
 #define JTAG_ID_PARTNO_SHIFT   12
 #define JTAG_ID_PARTNO_MASK(0x << 12)
+#define JTAG_ID_PARTNO_AM65X   0xbb5a
+#define JTAG_ID_PARTNO_J721E   0xbb64
+#define JTAG_ID_PARTNO_J7200   0xbb6d
+#define JTAG_ID_PARTNO_AM64X   0xbb38
+#define JTAG_ID_PARTNO_J721S2  0xbb75
+#define JTAG_ID_PARTNO_AM62X   0xbb7e
+#define JTAG_ID_PARTNO_AM62AX   0xbb8d
+
+#define K3_SOC_ID(id, ID) \
+static inline bool soc_is_##id(void) \
+{ \
+   u32 soc = (readl(CTRLMMR_WKUP_JTAG_ID) & \
+   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; \
+   return soc == JTAG_ID_PARTNO_##ID; \
+}
+K3_SOC_ID(am65x, AM65X)
+K3_SOC_ID(j721e, J721E)
+K3_SOC_ID(j7200, J7200)
+K3_SOC_ID(am64x, AM64X)
+K3_SOC_ID(j721s2, J721S2)
+K3_SOC_ID(am62x, AM62X)
+K3_SOC_ID(am62ax, AM62AX)
+
 #define K3_SEC_MGR_SYS_STATUS  0x44234100
 #define SYS_STATUS_DEV_TYPE_SHIFT  0
 #define SYS_STATUS_DEV_TYPE_MASK   (0xf)
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 0b5d606eaa2..d5d4b787b7d 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -15,9 +15,6 @@ int do_board_detect(void);
 void release_resources_for_core_shutdown(void);
 int fdt_disable_node(void *blob, char *node_path);
 
-bool soc_is_j721e(void);
-bool soc_is_j7200(void);
-
 void k3_spl_init(void);
 void k3_mem_init(void);
 bool check_rom_loaded_sysfw(void);
-- 
2.39.2



[PATCH v4 06/12] arm: mach-k3: Make release_resources_for_core_shutdown() common

2023-04-06 Thread Andrew Davis
This function is the same for each device when it needs to shutdown
the R5 core. Move this to the common section and move the remaining
device specific ID list to the device hardware include.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/am642_init.c | 51 -
 arch/arm/mach-k3/am654_init.c | 51 -
 arch/arm/mach-k3/common.c | 32 ++-
 arch/arm/mach-k3/include/mach/am62_hardware.h |  8 +++
 .../arm/mach-k3/include/mach/am62a_hardware.h |  8 +++
 arch/arm/mach-k3/include/mach/am64_hardware.h | 24 
 arch/arm/mach-k3/include/mach/am6_hardware.h  | 19 +++
 .../arm/mach-k3/include/mach/j721e_hardware.h | 19 +++
 .../mach-k3/include/mach/j721s2_hardware.h| 19 +++
 arch/arm/mach-k3/include/mach/sys_proto.h |  1 -
 arch/arm/mach-k3/j721e_init.c | 55 ---
 arch/arm/mach-k3/j721s2_init.c| 54 --
 12 files changed, 127 insertions(+), 214 deletions(-)

diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index 1bf7e163cc4..86aced54646 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -346,54 +346,3 @@ u32 spl_boot_device(void)
else
return __get_backup_bootmedia(devstat);
 }
-
-#if defined(CONFIG_SYS_K3_SPL_ATF)
-
-#define AM64X_DEV_RTI8 127
-#define AM64X_DEV_RTI9 128
-#define AM64X_DEV_R5FSS0_CORE0 121
-#define AM64X_DEV_R5FSS0_CORE1 122
-
-void release_resources_for_core_shutdown(void)
-{
-   struct ti_sci_handle *ti_sci = get_ti_sci_handle();
-   struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
-   struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
-   int ret;
-   u32 i;
-
-   const u32 put_device_ids[] = {
-   AM64X_DEV_RTI9,
-   AM64X_DEV_RTI8,
-   };
-
-   /* Iterate through list of devices to put (shutdown) */
-   for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
-   u32 id = put_device_ids[i];
-
-   ret = dev_ops->put_device(ti_sci, id);
-   if (ret)
-   panic("Failed to put device %u (%d)\n", id, ret);
-   }
-
-   const u32 put_core_ids[] = {
-   AM64X_DEV_R5FSS0_CORE1,
-   AM64X_DEV_R5FSS0_CORE0, /* Handle CPU0 after CPU1 */
-   };
-
-   /* Iterate through list of cores to put (shutdown) */
-   for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
-   u32 id = put_core_ids[i];
-
-   /*
-* Queue up the core shutdown request. Note that this call
-* needs to be followed up by an actual invocation of an WFE
-* or WFI CPU instruction.
-*/
-   ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
-   if (ret)
-   panic("Failed sending core %u shutdown message (%d)\n",
- id, ret);
-   }
-}
-#endif
diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
index 70059edb039..abd0c0bccbc 100644
--- a/arch/arm/mach-k3/am654_init.c
+++ b/arch/arm/mach-k3/am654_init.c
@@ -353,54 +353,3 @@ u32 spl_boot_device(void)
else
return __get_backup_bootmedia(devstat);
 }
-
-#ifdef CONFIG_SYS_K3_SPL_ATF
-
-#define AM6_DEV_MCU_RTI0   134
-#define AM6_DEV_MCU_RTI1   135
-#define AM6_DEV_MCU_ARMSS0_CPU0159
-#define AM6_DEV_MCU_ARMSS0_CPU1245
-
-void release_resources_for_core_shutdown(void)
-{
-   struct ti_sci_handle *ti_sci = get_ti_sci_handle();
-   struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
-   struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
-   int ret;
-   u32 i;
-
-   const u32 put_device_ids[] = {
-   AM6_DEV_MCU_RTI0,
-   AM6_DEV_MCU_RTI1,
-   };
-
-   /* Iterate through list of devices to put (shutdown) */
-   for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
-   u32 id = put_device_ids[i];
-
-   ret = dev_ops->put_device(ti_sci, id);
-   if (ret)
-   panic("Failed to put device %u (%d)\n", id, ret);
-   }
-
-   const u32 put_core_ids[] = {
-   AM6_DEV_MCU_ARMSS0_CPU1,
-   AM6_DEV_MCU_ARMSS0_CPU0,/* Handle CPU0 after CPU1 */
-   };
-
-   /* Iterate through list of cores to put (shutdown) */
-   for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
-   u32 id = put_core_ids[i];
-
-   /*
-* Queue up the core shutdown request. Note that this call
-* needs to be followed up by an actual invocation of an WFE
-* or WFI CPU instruction.
-*/
-   ret = proc_ops->proc_

[PATCH v4 03/12] soc: soc_ti_k3: Use hardware.h to remove definition duplication

2023-04-06 Thread Andrew Davis
The K3 JTAG and SoC ID information is already stored in the K3 arch
hardware file, include that and use its definitions here.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 drivers/soc/Kconfig |  2 +-
 drivers/soc/soc_ti_k3.c | 30 +-
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index acf555baaec..85dac9de78a 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -10,7 +10,7 @@ config SOC_DEVICE
  specific device variant in use.
 
 config SOC_DEVICE_TI_K3
-   depends on SOC_DEVICE
+   depends on SOC_DEVICE && ARCH_K3
bool "Enable SoC Device ID driver for TI K3 SoCs"
help
  This allows Texas Instruments Keystone 3 SoCs to identify
diff --git a/drivers/soc/soc_ti_k3.c b/drivers/soc/soc_ti_k3.c
index 8af0ac70519..42430d79a7a 100644
--- a/drivers/soc/soc_ti_k3.c
+++ b/drivers/soc/soc_ti_k3.c
@@ -8,21 +8,9 @@
 #include 
 #include 
 
+#include 
 #include 
 
-#define AM65X  0xbb5a
-#define J721E  0xbb64
-#define J7200  0xbb6d
-#define AM64X  0xbb38
-#define J721S2 0xbb75
-#define AM62X  0xbb7e
-#define AM62AX 0xbb8d
-
-#define JTAG_ID_VARIANT_SHIFT  28
-#define JTAG_ID_VARIANT_MASK   (0xf << 28)
-#define JTAG_ID_PARTNO_SHIFT   12
-#define JTAG_ID_PARTNO_MASK(0x << 12)
-
 struct soc_ti_k3_plat {
const char *family;
const char *revision;
@@ -36,25 +24,25 @@ static const char *get_family_string(u32 idreg)
soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
 
switch (soc) {
-   case AM65X:
+   case JTAG_ID_PARTNO_AM65X:
family = "AM65X";
break;
-   case J721E:
+   case JTAG_ID_PARTNO_J721E:
family = "J721E";
break;
-   case J7200:
+   case JTAG_ID_PARTNO_J7200:
family = "J7200";
break;
-   case AM64X:
+   case JTAG_ID_PARTNO_AM64X:
family = "AM64X";
break;
-   case J721S2:
+   case JTAG_ID_PARTNO_J721S2:
family = "J721S2";
break;
-   case AM62X:
+   case JTAG_ID_PARTNO_AM62X:
family = "AM62X";
break;
-   case AM62AX:
+   case JTAG_ID_PARTNO_AM62AX:
family = "AM62AX";
break;
default:
@@ -81,7 +69,7 @@ static const char *get_rev_string(u32 idreg)
soc = (idreg & JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
 
switch (soc) {
-   case J721E:
+   case JTAG_ID_PARTNO_J721E:
if (rev > ARRAY_SIZE(j721e_rev_string_map))
goto bail;
return j721e_rev_string_map[rev];
-- 
2.39.2



[PATCH v4 04/12] configs: j721x_evm: Remove unneeded check for SYS_K3_SPL_ATF

2023-04-06 Thread Andrew Davis
The TARGET_x_R5_EVM check is already enough to limit these defines to
only the correct builds. Remove the extra outer check.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 board/ti/j721e/j721e.env   | 2 --
 board/ti/j721s2/j721s2.env | 2 --
 2 files changed, 4 deletions(-)

diff --git a/board/ti/j721e/j721e.env b/board/ti/j721e/j721e.env
index 446395adfa5..f442d155842 100644
--- a/board/ti/j721e/j721e.env
+++ b/board/ti/j721e/j721e.env
@@ -21,7 +21,6 @@ args_all=setenv optargs earlycon=ns16550a,mmio32,0x0280
${mtdparts}
 run_kern=booti ${loadaddr} ${rd_spec} ${fdtaddr}
 
-#if CONFIG_SYS_K3_SPL_ATF
 #if CONFIG_TARGET_J721E_R5_EVM
 addr_mcur5f0_0load=0x8900
 name_mcur5f0_0fw=/lib/firmware/j7-mcu-r5f0_0-fw
@@ -29,7 +28,6 @@ name_mcur5f0_0fw=/lib/firmware/j7-mcu-r5f0_0-fw
 addr_mcur5f0_0load=0x8900
 name_mcur5f0_0fw=/lib/firmware/j7200-mcu-r5f0_0-fw
 #endif
-#endif
 
 boot=mmc
 mmcdev=1
diff --git a/board/ti/j721s2/j721s2.env b/board/ti/j721s2/j721s2.env
index 2152f8849f9..f4467770e40 100644
--- a/board/ti/j721s2/j721s2.env
+++ b/board/ti/j721s2/j721s2.env
@@ -25,12 +25,10 @@ boot=mmc
 mmcdev=1
 bootpart=1:2
 bootdir=/boot
-#if CONFIG_SYS_K3_SPL_ATF
 #if CONFIG_TARGET_J721S2_R5_EVM
 addr_mcur5f0_0load=0x8900
 name_mcur5f0_0fw=/lib/firmware/j7-mcu-r5f0_0-fw
 #endif
-#endif
 rd_spec=-
 init_mmc=run args_all args_mmc
 get_fdt_mmc=load mmc ${bootpart} ${fdtaddr} ${bootdir}/${name_fdt}
-- 
2.39.2



[PATCH v4 05/12] configs: j721s2_evm.h: Remove refrences to J7200 EVM

2023-04-06 Thread Andrew Davis
The J7200 EVM will not include this file, this J7200 checks look
to be a copy/paste errora from j721e_evm.h, which J7200 *can* include.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 include/configs/j721s2_evm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/configs/j721s2_evm.h b/include/configs/j721s2_evm.h
index 2fa93b79614..1e0da9f96c5 100644
--- a/include/configs/j721s2_evm.h
+++ b/include/configs/j721s2_evm.h
@@ -16,7 +16,7 @@
 #define CFG_SYS_SDRAM_BASE10x88000
 
 /* SPL Loader Configuration */
-#if defined(CONFIG_TARGET_J721S2_A72_EVM) || 
defined(CONFIG_TARGET_J7200_A72_EVM)
+#if defined(CONFIG_TARGET_J721S2_A72_EVM)
 #define CFG_SYS_UBOOT_BASE 0x5028
 /* Image load address in RAM for DFU boot*/
 #else
-- 
2.39.2



[PATCH v4 00/12] Remove K3 misc sys_proto.h header

2023-04-06 Thread Andrew Davis
Hello all,

Some minor cleanups with end patch removing sys_proto.h.
Why? Becouse I don't like headers of "miscellaneous".

Thanks,
Andrew

Changes from v3:
 - [2/12] Fix copy/paste error (thanks Christian)
 - add more tags and rebase on latest

Changes from v2:
 - Reworked patch [2/12] to use static and turned it into common macro
 - Removed "EEPROM" from comment as board detection can use other methods
 - Added more reviewed by tags

Changes from v1:
 - Added reviewed by tag
 - Rebased on latest

Andrew Davis (12):
  arm: mach-k3: Move MSMC fixup to SoC level
  arm: mach-k3: Move J721e SoC detection out of common section
  soc: soc_ti_k3: Use hardware.h to remove definition duplication
  configs: j721x_evm: Remove unneeded check for SYS_K3_SPL_ATF
  configs: j721s2_evm.h: Remove refrences to J7200 EVM
  arm: mach-k3: Make release_resources_for_core_shutdown() common
  arm: mach-k3: Move sysfw-loader.h out of mach includes
  arm: mach-k3: Add weak do_board_detect() to common file
  arm: mach-k3: Remove unused fdt_disable_node()
  arm: mach-k3: Move sdelay() and wait_on_value() declaration
  arm: mach-k3: Move J721s2 SPL init functions to mach-k3
  arm: mach-k3: Remove empty sys_proto.h include

 arch/arm/mach-k3/Kconfig  |   5 -
 arch/arm/mach-k3/am625_init.c |   2 +-
 arch/arm/mach-k3/am62a7_init.c|   2 +-
 arch/arm/mach-k3/am642_init.c |  59 +
 arch/arm/mach-k3/am654_init.c |  58 +
 arch/arm/mach-k3/common.c |  88 +++--
 arch/arm/mach-k3/common.h |   5 +-
 arch/arm/mach-k3/include/mach/am62_hardware.h |   8 ++
 .../arm/mach-k3/include/mach/am62a_hardware.h |   8 ++
 arch/arm/mach-k3/include/mach/am64_hardware.h |  24 
 arch/arm/mach-k3/include/mach/am6_hardware.h  |  19 +++
 arch/arm/mach-k3/include/mach/hardware.h  |  25 
 .../arm/mach-k3/include/mach/j721e_hardware.h |  19 +++
 .../mach-k3/include/mach/j721s2_hardware.h|  19 +++
 arch/arm/mach-k3/include/mach/sys_proto.h |  25 
 arch/arm/mach-k3/j721e_init.c |  66 +-
 arch/arm/mach-k3/j721s2_init.c| 121 ++
 arch/arm/mach-k3/security.c   |   1 -
 arch/arm/mach-k3/sysfw-loader.c   |   1 -
 .../mach-k3/{include/mach => }/sysfw-loader.h |   0
 board/siemens/iot2050/board.c |  12 +-
 board/ti/am62ax/evm.c |   1 -
 board/ti/am62x/evm.c  |   1 -
 board/ti/am64x/evm.c  |   1 -
 board/ti/am65x/evm.c  |  20 ---
 board/ti/common/Kconfig   |   1 -
 board/ti/j721e/evm.c  |  13 +-
 board/ti/j721e/j721e.env  |   2 -
 board/ti/j721s2/evm.c |  81 
 board/ti/j721s2/j721s2.env|   2 -
 configs/am65x_evm_a53_defconfig   |   2 +-
 configs/am65x_hs_evm_a53_defconfig|   2 +-
 configs/iot2050_pg1_defconfig |   1 +
 configs/iot2050_pg2_defconfig |   1 +
 configs/j7200_evm_a72_defconfig   |   1 +
 configs/j7200_hs_evm_a72_defconfig|   1 +
 configs/j721e_evm_a72_defconfig   |   1 +
 configs/j721e_hs_evm_a72_defconfig|   1 +
 configs/j721s2_evm_a72_defconfig  |   2 +-
 configs/j721s2_hs_evm_a72_defconfig   |   2 +-
 drivers/phy/phy-ti-am654.c|   1 -
 drivers/ram/k3-am654-ddrss.c  |   5 +-
 drivers/soc/Kconfig   |   2 +-
 drivers/soc/soc_ti_k3.c   |  30 ++---
 include/configs/j721s2_evm.h  |   2 +-
 45 files changed, 280 insertions(+), 463 deletions(-)
 delete mode 100644 arch/arm/mach-k3/include/mach/sys_proto.h
 rename arch/arm/mach-k3/{include/mach => }/sysfw-loader.h (100%)

-- 
2.39.2



Re: [PATCH v3 02/12] arm: mach-k3: Move J721e SoC detection out of common section

2023-04-06 Thread Andrew Davis

On 4/6/23 10:59 AM, Christian Gmeiner wrote:


This belongs in the J721e specific file as it is the only place
this is used. Any board level users should use the SOC driver.

While here, move the J721e and J7200 SoC IDs out of sys_proto.h
and into hardware.h. Use a macro borrowed from Rockchip and add
the rest of the SoC IDs for completeness and later use.

Signed-off-by: Andrew Davis 
---
  arch/arm/mach-k3/common.c | 20 --
  arch/arm/mach-k3/common.h |  3 ---
  arch/arm/mach-k3/include/mach/hardware.h  | 25 +++
  arch/arm/mach-k3/include/mach/sys_proto.h |  3 ---
  4 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 6870f13c520..6e084de692c 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -488,26 +488,6 @@ int print_cpuinfo(void)
  }
  #endif

-bool soc_is_j721e(void)
-{
-   u32 soc;
-
-   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
-   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
-
-   return soc == J721E;
-}
-
-bool soc_is_j7200(void)
-{
-   u32 soc;
-
-   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
-   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
-
-   return soc == J7200;
-}
-
  #ifdef CONFIG_ARM64
  void board_prep_linux(struct bootm_headers *images)
  {
diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
index 8f38fcef7f0..531be0be54c 100644
--- a/arch/arm/mach-k3/common.h
+++ b/arch/arm/mach-k3/common.h
@@ -9,9 +9,6 @@
  #include 
  #include 

-#define J721E  0xbb64
-#define J7200  0xbb6d
-
  struct fwl_data {
 const char *name;
 u16 fwl_id;
diff --git a/arch/arm/mach-k3/include/mach/hardware.h 
b/arch/arm/mach-k3/include/mach/hardware.h
index 2c60ef85432..4f7bf68f5b6 100644
--- a/arch/arm/mach-k3/include/mach/hardware.h
+++ b/arch/arm/mach-k3/include/mach/hardware.h
@@ -6,6 +6,8 @@
  #ifndef _ASM_ARCH_HARDWARE_H_
  #define _ASM_ARCH_HARDWARE_H_

+#include 
+
  #ifdef CONFIG_SOC_K3_AM654
  #include "am6_hardware.h"
  #endif
@@ -36,6 +38,29 @@
  #define JTAG_ID_VARIANT_MASK   (0xf << 28)
  #define JTAG_ID_PARTNO_SHIFT   12
  #define JTAG_ID_PARTNO_MASK(0x << 12)
+#define JTAG_ID_PARTNO_AM65X   0xbb5a
+#define JTAG_ID_PARTNO_J721E   0xbb64
+#define JTAG_ID_PARTNO_J7200   0xbb6d
+#define JTAG_ID_PARTNO_AM64X   0xbb38
+#define JTAG_ID_PARTNO_J721S2  0xbb75
+#define JTAG_ID_PARTNO_AM62X   0xbb7e
+#define JTAG_ID_PARTNO_AM62AX   0xbb8d
+
+#define K3_SOC_ID(id, ID) \
+static inline bool soc_is_##id(void) \
+{ \
+   u32 soc = (readl(CTRLMMR_WKUP_JTAG_ID) & \
+   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; \
+   return soc == JTAG_ID_PARTNO_J7200; \


This is not what you want. Maybe
return soc == JTAG_ID_PARTNO_##ID; \



Ah, copy/paste error got me 😄 good catch, v4 on the way..

Thanks,
Andrew


+}
+K3_SOC_ID(am65x, AM65X)
+K3_SOC_ID(j721e, J721E)
+K3_SOC_ID(j7200, J7200)
+K3_SOC_ID(am64x, AM64X)
+K3_SOC_ID(j721s2, J721S2)
+K3_SOC_ID(am62x, AM62X)
+K3_SOC_ID(am62ax, AM62AX)
+
  #define K3_SEC_MGR_SYS_STATUS  0x44234100
  #define SYS_STATUS_DEV_TYPE_SHIFT  0
  #define SYS_STATUS_DEV_TYPE_MASK   (0xf)
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 0b5d606eaa2..d5d4b787b7d 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -15,9 +15,6 @@ int do_board_detect(void);
  void release_resources_for_core_shutdown(void);
  int fdt_disable_node(void *blob, char *node_path);

-bool soc_is_j721e(void);
-bool soc_is_j7200(void);
-
  void k3_spl_init(void);
  void k3_mem_init(void);
  bool check_rom_loaded_sysfw(void);
--
2.39.2






[PATCH 1/2] rockchip: rng: add trngv1 for rk3588

2023-04-06 Thread Chris Morgan
From: Chris Morgan 

This adds support for the TRNG found in the RK3588 SoC to the
rockchip_rng driver so that it can be used for things such as
seeding randomness to Linux.

This code was taken wholesale from the Rockchip BSP U-Boot source
located here:
https://github.com/rockchip-linux/u-boot/commit/09f31aed858c36a8a5ee20789712e65bb4762068

Tested on an Indiedroid Nova with an RK3588s.

Signed-off-by: Lin Jinhan 
Signed-off-by: Chris Morgan 
---
 drivers/rng/rockchip_rng.c | 120 ++---
 1 file changed, 111 insertions(+), 9 deletions(-)

diff --git a/drivers/rng/rockchip_rng.c b/drivers/rng/rockchip_rng.c
index 800150f114..705b424cf3 100644
--- a/drivers/rng/rockchip_rng.c
+++ b/drivers/rng/rockchip_rng.c
@@ -43,9 +43,41 @@
 #define CRYPTO_V2_RNG_DOUT_0   0x0410
 /* end of CRYPTO V2 register define */
 
+/* start of TRNG V1 register define */
+#define TRNG_V1_CTRL   0x
+#define TRNG_V1_CTRL_NOP   _SBF(0, 0x00)
+#define TRNG_V1_CTRL_RAND  _SBF(0, 0x01)
+#define TRNG_V1_CTRL_SEED  _SBF(0, 0x02)
+
+#define TRNG_V1_MODE   0x0008
+#define TRNG_V1_MODE_128_BIT   _SBF(3, 0x00)
+#define TRNG_V1_MODE_256_BIT   _SBF(3, 0x01)
+
+#define TRNG_V1_IE 0x0010
+#define TRNG_V1_IE_GLBL_EN BIT(31)
+#define TRNG_V1_IE_SEED_DONE_ENBIT(1)
+#define TRNG_V1_IE_RAND_RDY_EN BIT(0)
+
+#define TRNG_V1_ISTAT  0x0014
+#define TRNG_V1_ISTAT_RAND_RDY BIT(0)
+
+/* RAND0 ~ RAND7 */
+#define TRNG_V1_RAND0  0x0020
+#define TRNG_V1_RAND7  0x003C
+
+#define TRNG_V1_AUTO_RQSTS 0x0060
+
+#define TRNG_V1_VERSION0x00F0
+#define TRNG_v1_VERSION_CODE   0x46BC
+/* end of TRNG V1 register define */
+
 #define RK_RNG_TIME_OUT5  /* max 50ms */
 
+#define trng_write(pdata, pos, val)writel(val, (pdata)->base + (pos))
+#define trng_read(pdata, pos)  readl((pdata)->base + (pos))
+
 struct rk_rng_soc_data {
+   int (*rk_rng_init)(struct udevice *dev);
int (*rk_rng_read)(struct udevice *dev, void *data, size_t len);
 };
 
@@ -75,7 +107,7 @@ static int rk_rng_read_regs(fdt_addr_t addr, void *buf, 
size_t size)
return 0;
 }
 
-static int rk_v1_rng_read(struct udevice *dev, void *data, size_t len)
+static int rk_cryptov1_rng_read(struct udevice *dev, void *data, size_t len)
 {
struct rk_rng_plat *pdata = dev_get_priv(dev);
u32 reg = 0;
@@ -106,7 +138,7 @@ exit:
return 0;
 }
 
-static int rk_v2_rng_read(struct udevice *dev, void *data, size_t len)
+static int rk_cryptov2_rng_read(struct udevice *dev, void *data, size_t len)
 {
struct rk_rng_plat *pdata = dev_get_priv(dev);
u32 reg = 0;
@@ -140,6 +172,63 @@ exit:
return retval;
 }
 
+static int rk_trngv1_init(struct udevice *dev)
+{
+   u32 status, version;
+   u32 auto_reseed_cnt = 1000;
+   struct rk_rng_plat *pdata = dev_get_priv(dev);
+
+   version = trng_read(pdata, TRNG_V1_VERSION);
+   if (version != TRNG_v1_VERSION_CODE) {
+   printf("wrong trng version, expected = %08x, actual = %08x",
+  TRNG_V1_VERSION, version);
+   return -EFAULT;
+   }
+
+   /* wait in case of RND_RDY triggered at firs power on */
+   readl_poll_timeout(pdata->base + TRNG_V1_ISTAT, status,
+  (status & TRNG_V1_ISTAT_RAND_RDY),
+  RK_RNG_TIME_OUT);
+
+   /* clear RAND_RDY flag for first power on */
+   trng_write(pdata, TRNG_V1_ISTAT, status);
+
+   /* auto reseed after (auto_reseed_cnt * 16) byte rand generate */
+   trng_write(pdata, TRNG_V1_AUTO_RQSTS, auto_reseed_cnt);
+
+   return 0;
+}
+
+static int rk_trngv1_rng_read(struct udevice *dev, void *data, size_t len)
+{
+   struct rk_rng_plat *pdata = dev_get_priv(dev);
+   u32 reg = 0;
+   int retval;
+
+   if (len > RK_HW_RNG_MAX)
+   return -EINVAL;
+
+   trng_write(pdata, TRNG_V1_MODE, TRNG_V1_MODE_256_BIT);
+   trng_write(pdata, TRNG_V1_CTRL, TRNG_V1_CTRL_RAND);
+
+   retval = readl_poll_timeout(pdata->base + TRNG_V1_ISTAT, reg,
+   (reg & TRNG_V1_ISTAT_RAND_RDY),
+   RK_RNG_TIME_OUT);
+   /* clear ISTAT */
+   trng_write(pdata, TRNG_V1_ISTAT, reg);
+
+   if (retval)
+   goto exit;
+
+   rk_rng_read_regs(pdata->base + TRNG_V1_RAND0, data, len);
+
+exit:
+   /* close TRNG */
+   trng_write(pdata, TRNG_V1_CTRL, TRNG_V1_CTRL_NOP);
+
+   return retval;
+}
+
 static int rockchip_rng_read(struct udevice *dev, void *data, size_t len)
 {
unsigned char *buf = data;
@@ -184,18 +27

[PATCH 2/2] ARM: dts: rockchip: rk3588s-u-boot: Add rng node

2023-04-06 Thread Chris Morgan
From: Chris Morgan 

Add a node for the trng found on RK3588 SoCs.

Signed-off-by: Chris Morgan 
---
 arch/arm/dts/rk3588s-u-boot.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/dts/rk3588s-u-boot.dtsi b/arch/arm/dts/rk3588s-u-boot.dtsi
index f880f4a167..43aeeb4de3 100644
--- a/arch/arm/dts/rk3588s-u-boot.dtsi
+++ b/arch/arm/dts/rk3588s-u-boot.dtsi
@@ -43,6 +43,12 @@
reg = <0x07 0x10>;
};
};
+
+   rng: rng@fe378000 {
+   compatible = "rockchip,trngv1";
+   reg = <0x0 0xfe378000 0x0 0x200>;
+   status = "disabled";
+   };
 };
 
 &xin24m {
-- 
2.34.1



[PATCH 0/2] Add RK3588 TRNG

2023-04-06 Thread Chris Morgan
From: Chris Morgan 

Add support for the RK3588 TRNG. The code was taken directly from the
Rockchip BSP U-Boot source.

Chris Morgan (2):
  rockchip: rng: add trngv1 for rk3588
  ARM: dts: rockchip: rk3588s-u-boot: Add rng node

 arch/arm/dts/rk3588s-u-boot.dtsi |   6 ++
 drivers/rng/rockchip_rng.c   | 120 ---
 2 files changed, 117 insertions(+), 9 deletions(-)

-- 
2.34.1



[PATCH] arm: mx6: module_fuse: fix build failure due to wrong argument name

2023-04-06 Thread Giulio Benetti
nodeoff variable should be variable off returned by fdt_path_offset() so
let's rename it to off.

Signed-off-by: Giulio Benetti 
---
 arch/arm/mach-imx/mx6/module_fuse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/mx6/module_fuse.c 
b/arch/arm/mach-imx/mx6/module_fuse.c
index 0f4565e311..b58f11c1e5 100644
--- a/arch/arm/mach-imx/mx6/module_fuse.c
+++ b/arch/arm/mach-imx/mx6/module_fuse.c
@@ -206,7 +206,7 @@ int ft_system_setup(void *blob, struct bd_info *bd)
if (off < 0)
continue; /* Not found, skip it */
 add_status:
-   rc = fdt_setprop(blob, nodeoff, "status", status,
+   rc = fdt_setprop(blob, off, "status", status,
 strlen(status) + 1);
if (rc) {
if (rc == -FDT_ERR_NOSPACE) {
-- 
2.34.1



Re: [PATCH v3 12/12] arm: mach-k3: Remove empty sys_proto.h include

2023-04-06 Thread Christian Gmeiner
>
> This header file is now empty, remove it.
>
> Signed-off-by: Andrew Davis 

Reviewed-by: Christian Gmeiner 

> ---
>  arch/arm/mach-k3/am642_init.c |  2 --
>  arch/arm/mach-k3/am654_init.c |  1 -
>  arch/arm/mach-k3/common.c |  1 -
>  arch/arm/mach-k3/include/mach/sys_proto.h | 10 --
>  arch/arm/mach-k3/j721e_init.c |  1 -
>  arch/arm/mach-k3/j721s2_init.c|  1 -
>  arch/arm/mach-k3/security.c   |  1 -
>  arch/arm/mach-k3/sysfw-loader.c   |  1 -
>  board/siemens/iot2050/board.c |  1 -
>  board/ti/am62ax/evm.c |  1 -
>  board/ti/am62x/evm.c  |  1 -
>  board/ti/am64x/evm.c  |  1 -
>  board/ti/am65x/evm.c  |  2 --
>  board/ti/j721e/evm.c  |  2 --
>  board/ti/j721s2/evm.c |  2 --
>  drivers/phy/phy-ti-am654.c|  1 -
>  drivers/ram/k3-am654-ddrss.c  |  1 -
>  17 files changed, 30 deletions(-)
>  delete mode 100644 arch/arm/mach-k3/include/mach/sys_proto.h
>
> diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
> index ef84aad819c..5d53358cf26 100644
> --- a/arch/arm/mach-k3/am642_init.c
> +++ b/arch/arm/mach-k3/am642_init.c
> @@ -13,9 +13,7 @@
>  #include 
>  #include 
>  #include "sysfw-loader.h"
> -#include 
>  #include "common.h"
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
> index 2336da4b454..0d3889cde2b 100644
> --- a/arch/arm/mach-k3/am654_init.c
> +++ b/arch/arm/mach-k3/am654_init.c
> @@ -14,7 +14,6 @@
>  #include 
>  #include 
>  #include "sysfw-loader.h"
> -#include 
>  #include "common.h"
>  #include 
>  #include 
> diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
> index 9f2f5a98771..e29e51b7042 100644
> --- a/arch/arm/mach-k3/common.c
> +++ b/arch/arm/mach-k3/common.c
> @@ -19,7 +19,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
> b/arch/arm/mach-k3/include/mach/sys_proto.h
> deleted file mode 100644
> index 5638c6f8c8a..000
> --- a/arch/arm/mach-k3/include/mach/sys_proto.h
> +++ /dev/null
> @@ -1,10 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0+ */
> -/*
> - * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
> - * Andreas Dannenberg 
> - */
> -
> -#ifndef _SYS_PROTO_H_
> -#define _SYS_PROTO_H_
> -
> -#endif
> diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
> index 31d324e2179..9bba5f79545 100644
> --- a/arch/arm/mach-k3/j721e_init.c
> +++ b/arch/arm/mach-k3/j721e_init.c
> @@ -14,7 +14,6 @@
>  #include 
>  #include "sysfw-loader.h"
>  #include "common.h"
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
> index 175ac4028a0..001d9466c20 100644
> --- a/arch/arm/mach-k3/j721s2_init.c
> +++ b/arch/arm/mach-k3/j721s2_init.c
> @@ -14,7 +14,6 @@
>  #include 
>  #include "sysfw-loader.h"
>  #include "common.h"
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/arch/arm/mach-k3/security.c b/arch/arm/mach-k3/security.c
> index 092588f4b5e..6179f7373aa 100644
> --- a/arch/arm/mach-k3/security.c
> +++ b/arch/arm/mach-k3/security.c
> @@ -17,7 +17,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>
>  #include "common.h"
> diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
> index c4c5c371100..9be2d9eaea2 100644
> --- a/arch/arm/mach-k3/sysfw-loader.c
> +++ b/arch/arm/mach-k3/sysfw-loader.c
> @@ -23,7 +23,6 @@
>  #include 
>
>  #include 
> -#include 
>  #include "common.h"
>
>  DECLARE_GLOBAL_DATA_PTR;
> diff --git a/board/siemens/iot2050/board.c b/board/siemens/iot2050/board.c
> index 1ba3e90c6fc..2653e107450 100644
> --- a/board/siemens/iot2050/board.c
> +++ b/board/siemens/iot2050/board.c
> @@ -21,7 +21,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/board/ti/am62ax/evm.c b/board/ti/am62ax/evm.c
> index beef3f2f3da..f2dd3b4192e 100644
> --- a/board/ti/am62ax/evm.c
> +++ b/board/ti/am62ax/evm.c
> @@ -7,7 +7,6 @@
>   */
>
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/board/ti/am62x/evm.c b/board/ti/am62x/evm.c
> index 20b2a701223..034fbed3aa4 100644
> --- a/board/ti/am62x/evm.c
> +++ b/board/ti/am62x/evm.c
> @@ -15,7 +15,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>
>  DECLARE_GLOBAL_DATA_PTR;
> diff --git a/board/ti/am64x/evm.c b/board/ti/am64x/evm.c
> index c88139ac7ac..b63792e 100644
> --- a/board/ti/am64x/evm.c
> +++ b/board/ti/am64x/evm.c
> @@ -14,7 +14,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>
>  #include "../common/board_detect.h"
> diff --git a/board/ti/am65x/evm.c b/bo

Re: [PATCH v3 08/12] arm: mach-k3: Add weak do_board_detect() to common file

2023-04-06 Thread Christian Gmeiner
>
> This matches how it was done for pre-K3 TI platforms and it allows
> us to move the forward declaration out of sys_proto.h.
>
> It also removes the need for K3_BOARD_DETECT as one is free to simply
> override the weak function in their board files as needed.
>
> Signed-off-by: Andrew Davis 

Reviewed-by: Christian Gmeiner 

> ---
>  arch/arm/mach-k3/Kconfig  |  5 -
>  arch/arm/mach-k3/am642_init.c |  4 ++--
>  arch/arm/mach-k3/am654_init.c |  4 ++--
>  arch/arm/mach-k3/common.c | 10 ++
>  arch/arm/mach-k3/common.h |  2 ++
>  arch/arm/mach-k3/include/mach/sys_proto.h |  2 --
>  arch/arm/mach-k3/j721e_init.c |  8 
>  board/ti/common/Kconfig   |  1 -
>  8 files changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> index 7edbac26ccc..a8c3a593d57 100644
> --- a/arch/arm/mach-k3/Kconfig
> +++ b/arch/arm/mach-k3/Kconfig
> @@ -187,11 +187,6 @@ config K3_X509_SWRV
> help
>   SWRV for X509 certificate used for boot images
>
> -config K3_BOARD_DETECT
> -   bool "Support for Board detection"
> -   help
> -  Support for board detection.
> -
>  source "board/ti/am65x/Kconfig"
>  source "board/ti/am64x/Kconfig"
>  source "board/ti/am62x/Kconfig"
> diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
> index c7720cbaf35..ef84aad819c 100644
> --- a/arch/arm/mach-k3/am642_init.c
> +++ b/arch/arm/mach-k3/am642_init.c
> @@ -100,8 +100,8 @@ void do_dt_magic(void)
>  {
> int ret, rescan;
>
> -   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
> -   do_board_detect();
> +   /* Perform board detection */
> +   do_board_detect();
>
> /*
>  * Board detection has been done.
> diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
> index 12d74635cb0..2336da4b454 100644
> --- a/arch/arm/mach-k3/am654_init.c
> +++ b/arch/arm/mach-k3/am654_init.c
> @@ -245,8 +245,8 @@ void board_init_f(ulong dummy)
> /* Output System Firmware version info */
> k3_sysfw_print_ver();
>
> -   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
> -   do_board_detect();
> +   /* Perform board detection */
> +   do_board_detect();
>
>  #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
> ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
> diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
> index 4f2e14c3105..115f5959734 100644
> --- a/arch/arm/mach-k3/common.c
> +++ b/arch/arm/mach-k3/common.c
> @@ -636,3 +636,13 @@ int misc_init_r(void)
>
> return 0;
>  }
> +
> +/**
> + * do_board_detect() - Detect board description
> + *
> + * Function to detect board description. This is expected to be
> + * overridden in the SoC family board file where desired.
> + */
> +void __weak do_board_detect(void)
> +{
> +}
> diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
> index 531be0be54c..130f5021123 100644
> --- a/arch/arm/mach-k3/common.h
> +++ b/arch/arm/mach-k3/common.h
> @@ -35,3 +35,5 @@ void mmr_unlock(phys_addr_t base, u32 partition);
>  bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data);
>  enum k3_device_type get_device_type(void);
>  void ti_secure_image_post_process(void **p_image, size_t *p_size);
> +struct ti_sci_handle *get_ti_sci_handle(void);
> +void do_board_detect(void);
> diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
> b/arch/arm/mach-k3/include/mach/sys_proto.h
> index 8cc75b636b5..939de0f79b4 100644
> --- a/arch/arm/mach-k3/include/mach/sys_proto.h
> +++ b/arch/arm/mach-k3/include/mach/sys_proto.h
> @@ -10,8 +10,6 @@
>  void sdelay(unsigned long loops);
>  u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
>   u32 bound);
> -struct ti_sci_handle *get_ti_sci_handle(void);
> -int do_board_detect(void);
>  int fdt_disable_node(void *blob, char *node_path);
>
>  void k3_spl_init(void);
> diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
> index eec5b726b95..31d324e2179 100644
> --- a/arch/arm/mach-k3/j721e_init.c
> +++ b/arch/arm/mach-k3/j721e_init.c
> @@ -140,8 +140,8 @@ void do_dt_magic(void)
> int ret, rescan, mmc_dev = -1;
> static struct mmc *mmc;
>
> -   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
> -   do_board_detect();
> +   /* Perform board detection */
> +   do_board_detect();
>
> /*
>  * Board detection has been done.
> @@ -267,8 +267,8 @@ void board_init_f(ulong dummy)
> /* Output System Firmware version info */
> k3_sysfw_print_ver();
>
> -   if (IS_ENABLED(CONFIG_K3_BOARD_DETECT))
> -   do_board_detect();
> +   /* Perform board detection */
> +   do_board_detect();
>
>  #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
> ret = uclass_get_device_by_driver(UCLASS_MISC

Re: [PATCH v3 02/12] arm: mach-k3: Move J721e SoC detection out of common section

2023-04-06 Thread Christian Gmeiner
>
> This belongs in the J721e specific file as it is the only place
> this is used. Any board level users should use the SOC driver.
>
> While here, move the J721e and J7200 SoC IDs out of sys_proto.h
> and into hardware.h. Use a macro borrowed from Rockchip and add
> the rest of the SoC IDs for completeness and later use.
>
> Signed-off-by: Andrew Davis 
> ---
>  arch/arm/mach-k3/common.c | 20 --
>  arch/arm/mach-k3/common.h |  3 ---
>  arch/arm/mach-k3/include/mach/hardware.h  | 25 +++
>  arch/arm/mach-k3/include/mach/sys_proto.h |  3 ---
>  4 files changed, 25 insertions(+), 26 deletions(-)
>
> diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
> index 6870f13c520..6e084de692c 100644
> --- a/arch/arm/mach-k3/common.c
> +++ b/arch/arm/mach-k3/common.c
> @@ -488,26 +488,6 @@ int print_cpuinfo(void)
>  }
>  #endif
>
> -bool soc_is_j721e(void)
> -{
> -   u32 soc;
> -
> -   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
> -   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
> -
> -   return soc == J721E;
> -}
> -
> -bool soc_is_j7200(void)
> -{
> -   u32 soc;
> -
> -   soc = (readl(CTRLMMR_WKUP_JTAG_ID) &
> -   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
> -
> -   return soc == J7200;
> -}
> -
>  #ifdef CONFIG_ARM64
>  void board_prep_linux(struct bootm_headers *images)
>  {
> diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
> index 8f38fcef7f0..531be0be54c 100644
> --- a/arch/arm/mach-k3/common.h
> +++ b/arch/arm/mach-k3/common.h
> @@ -9,9 +9,6 @@
>  #include 
>  #include 
>
> -#define J721E  0xbb64
> -#define J7200  0xbb6d
> -
>  struct fwl_data {
> const char *name;
> u16 fwl_id;
> diff --git a/arch/arm/mach-k3/include/mach/hardware.h 
> b/arch/arm/mach-k3/include/mach/hardware.h
> index 2c60ef85432..4f7bf68f5b6 100644
> --- a/arch/arm/mach-k3/include/mach/hardware.h
> +++ b/arch/arm/mach-k3/include/mach/hardware.h
> @@ -6,6 +6,8 @@
>  #ifndef _ASM_ARCH_HARDWARE_H_
>  #define _ASM_ARCH_HARDWARE_H_
>
> +#include 
> +
>  #ifdef CONFIG_SOC_K3_AM654
>  #include "am6_hardware.h"
>  #endif
> @@ -36,6 +38,29 @@
>  #define JTAG_ID_VARIANT_MASK   (0xf << 28)
>  #define JTAG_ID_PARTNO_SHIFT   12
>  #define JTAG_ID_PARTNO_MASK(0x << 12)
> +#define JTAG_ID_PARTNO_AM65X   0xbb5a
> +#define JTAG_ID_PARTNO_J721E   0xbb64
> +#define JTAG_ID_PARTNO_J7200   0xbb6d
> +#define JTAG_ID_PARTNO_AM64X   0xbb38
> +#define JTAG_ID_PARTNO_J721S2  0xbb75
> +#define JTAG_ID_PARTNO_AM62X   0xbb7e
> +#define JTAG_ID_PARTNO_AM62AX   0xbb8d
> +
> +#define K3_SOC_ID(id, ID) \
> +static inline bool soc_is_##id(void) \
> +{ \
> +   u32 soc = (readl(CTRLMMR_WKUP_JTAG_ID) & \
> +   JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT; \
> +   return soc == JTAG_ID_PARTNO_J7200; \

This is not what you want. Maybe
   return soc == JTAG_ID_PARTNO_##ID; \

> +}
> +K3_SOC_ID(am65x, AM65X)
> +K3_SOC_ID(j721e, J721E)
> +K3_SOC_ID(j7200, J7200)
> +K3_SOC_ID(am64x, AM64X)
> +K3_SOC_ID(j721s2, J721S2)
> +K3_SOC_ID(am62x, AM62X)
> +K3_SOC_ID(am62ax, AM62AX)
> +
>  #define K3_SEC_MGR_SYS_STATUS  0x44234100
>  #define SYS_STATUS_DEV_TYPE_SHIFT  0
>  #define SYS_STATUS_DEV_TYPE_MASK   (0xf)
> diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
> b/arch/arm/mach-k3/include/mach/sys_proto.h
> index 0b5d606eaa2..d5d4b787b7d 100644
> --- a/arch/arm/mach-k3/include/mach/sys_proto.h
> +++ b/arch/arm/mach-k3/include/mach/sys_proto.h
> @@ -15,9 +15,6 @@ int do_board_detect(void);
>  void release_resources_for_core_shutdown(void);
>  int fdt_disable_node(void *blob, char *node_path);
>
> -bool soc_is_j721e(void);
> -bool soc_is_j7200(void);
> -
>  void k3_spl_init(void);
>  void k3_mem_init(void);
>  bool check_rom_loaded_sysfw(void);
> --
> 2.39.2
>


-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy


Re: [PATCH v2 1/4] sunxi: spl: Disable padding from SPL_PAD_TO

2023-04-06 Thread Andre Przywara
On Sun, 22 Jan 2023 15:15:27 -0600
Samuel Holland  wrote:

Hi Samuel,

> Starting with H6, Allwinner removed the artificial 32 KiB SPL size limit
> from the boot ROM. Now SPL size is only limited by the available SRAM.
> This limit ranges from 152 KiB on H6 to a whopping 2052 KiB on R329. To
> take advantage of this additional space, we must increase SPL_MAX_SIZE.
> Since we do not want to unnecessarily pad SPL out to these giant sizes,
> we must set SPL_PAD_TO to zero. This causes no problems because binman
> already takes care of appending the SPL payload at the right offset.

So this patch breaks compilation, unless we have CONFIG_SPL_LOAD_FIT=1.
Since this becomes only possible for ARM32 at the end of the series, this
would need to move there, at the very least.
But then it still would break if someone de-selects this option (it's
"imply" only).
I don't have time at the moment to deep dive into this, if someone has an
idea how to fix this without forcing SPL_LOAD_FIT, I am all ears.

Cheers,
Andre

> Signed-off-by: Samuel Holland 
> ---
> 
> Changes in v2:
>  - New patch for v2
> 
>  common/spl/Kconfig | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> index 3c2af453ab..a7c55f8c4c 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -97,8 +97,7 @@ config SPL_PAD_TO
>   default 0x31000 if ARCH_MX6 && MX6_OCRAM_256KB
>   default 0x11000 if ARCH_MX7 || (ARCH_MX6 && !MX6_OCRAM_256KB)
>   default 0x1 if ARCH_KEYSTONE
> - default 0x8000 if ARCH_SUNXI && !MACH_SUN50I_H616
> - default 0x0 if ARCH_MTMIPS
> + default 0x0 if ARCH_MTMIPS || ARCH_SUNXI
>   default TPL_MAX_SIZE if TPL_MAX_SIZE > SPL_MAX_SIZE
>   default SPL_MAX_SIZE
>   help



Re: [PATCH v2 1/3] fdt: validate/fix cells count on mtdpart fixup

2023-04-06 Thread Tom Rini
On Tue, Apr 04, 2023 at 06:18:03PM +0200, Francesco Dolcini wrote:
> +Stefano
> 
> On Mon, Feb 06, 2023 at 06:17:31PM -0500, Tom Rini wrote:
> > On Mon, Feb 06, 2023 at 11:48:36PM +0100, Francesco Dolcini wrote:
> > 
> > > From: Francesco Dolcini 
> > > 
> > > Fixup #size-cells value when updating the MTD partitions, this is
> > > required to prevent issues in case the MTD parent set #size-cells to
> > > zero.
> > > This could happen for example in the legacy case in which the partitions
> > > are created as direct child of the mtd node and that specific node has
> > > no children. Recent clean-up on Linux device tree files created a boot
> > > regression on colibri-imx7 [0].
> > > 
> > > This fixup has the limitation to assume 32-bit (#size-cells=1)
> > > addressing, therefore it will not work with device bigger than 4GiB.
> > > 
> > > This change also enforce #address-cells to be the same as #size-cells,
> > > this was already silently enforced by fdt_node_set_part_info(), now this
> > > is checked explicitly and partition fixup will just fail in such case.
> > > 
> > > When the partition list is static the preferred way to pass the mtd
> > > partition list to the kernel is to either define those in the source DTS
> > > file or use mtdparts= in the command line.
> > > Tweaking the DT from U-Boot should be avoided, unless some dynamic
> > > changes are required, since it proved to be problematic when not
> > > following the evolution of the "standard".
> > > 
> > > Link: 
> > > https://lore.kernel.org/all/y4dgbtgnwpm6s...@francesco-nb.int.toradex.com/
> > > Link: 
> > > https://lore.kernel.org/all/20221202071900.1143950-1-france...@dolcini.it/
> > > Cc: Marek Vasut 
> > > Cc: Miquel Raynal 
> > > Signed-off-by: Francesco Dolcini 
> > > ---
> > > v2: improved commit message
> > > ---
> > >  common/fdt_support.c | 45 ++--
> > >  1 file changed, 35 insertions(+), 10 deletions(-)
> > 
> > I'm dropping the linux-mtd list here and adding a bunch more platform
> > maintainers. In general, calling fdt_fixup_mtdparts is the wrong choice.
> > I see we do have a few cases in U-Boot where we're clearly doing
> > something dynamic to the partition table, but it looks like at first
> > glance most callers are using this hook when they should either be
> > having the partition map in the device tree properly (and using one of
> > the appropriate bindings) or passing the map in via the kernel command
> > line. I would like to ask everyone I've added to the list here to
> > please audit your platform and update it as needed. Thanks!
> 
> Hello Tom,
> what should we do with this patch? No feedback so far, apart this email
> from you.
> 
> Stefano: maybe you can pick patches 2 and 3 ?

I thought someone chimed in for the STM32 side? But yes, patches 2 and 3
should get picked up for sure.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 1/1] arm: dts: icnova-a20-adb4006: Add board support

2023-04-06 Thread Ludwig Kormann
Add board support for ICnova A20 SomPi compute module on
ICnova ADB4006 development board.

Specification:
SoM
- Processor: Allwinner A20 Cortex-A7 Dual Core at 1GHz
- 512MB DDR3 RAM
- Fast Ethernet (Phy: Realtek RTL8201CP)
ADB4006
- I2C
- 2x USB 2.0
- 1x Fast Ethernet port
- 1x SATA
- 2x buttons
- 2x LEDS
- serial console
- HDMI
- µSD-Card slot
- Audio Line-In / Line-Out
- GPIO pinheaders

https://wiki.in-circuit.de/index.php5?title=ICnova_ADB4006
https://wiki.in-circuit.de/index.php5?title=ICnova_A20_SODIMM
Signed-off-by: Ludwig Kormann 
---
 arch/arm/dts/Makefile |   1 +
 arch/arm/dts/sun7i-a20-icnova-a20-adb4006.dts | 248 ++
 board/sunxi/MAINTAINERS   |   5 +
 configs/icnova-a20-adb4006_defconfig  |  25 ++
 4 files changed, 279 insertions(+)
 create mode 100644 arch/arm/dts/sun7i-a20-icnova-a20-adb4006.dts
 create mode 100644 configs/icnova-a20-adb4006_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 0a9b1f7749..47dcaff780 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -623,6 +623,7 @@ dtb-$(CONFIG_MACH_SUN7I) += \
sun7i-a20-haoyu-marsboard.dtb \
sun7i-a20-hummingbird.dtb \
sun7i-a20-i12-tvbox.dtb \
+   sun7i-a20-icnova-a20-adb4006.dtb \
sun7i-a20-icnova-swac.dtb \
sun7i-a20-itead-ibox.dtb \
sun7i-a20-lamobo-r1.dtb \
diff --git a/arch/arm/dts/sun7i-a20-icnova-a20-adb4006.dts 
b/arch/arm/dts/sun7i-a20-icnova-a20-adb4006.dts
new file mode 100644
index 00..e43df838ec
--- /dev/null
+++ b/arch/arm/dts/sun7i-a20-icnova-a20-adb4006.dts
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2023 Ludwig Kormann 
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file 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.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+#include "sun7i-a20.dtsi"
+#include "sunxi-common-regulators.dtsi"
+
+#include 
+#include 
+
+/ {
+   model = "In-Circuit ICnova A20 ADB4006";
+   compatible = "in-circuit,icnova-a20-adb4006", "incircuit,icnova-a20",
+"allwinner,sun7i-a20";
+
+   aliases {
+   serial0 = &uart0;
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   hdmi-connector {
+   compatible = "hdmi-connector";
+   type = "a";
+
+   port {
+   hdmi_con_in: endpoint {
+   remote-endpoint = <&hdmi_out_con>;
+   };
+   };
+   };
+
+   leds {
+   compatible = "gpio-leds";
+   pinctrl-names = "default";
+   pinctrl-0 = <&led_pins_icnova_a20_adb4006>;
+
+   led-0 {
+   label = "icnova_a20_adb4006:yellow:usr";
+   gpios = <&pio 7 21 GPIO_ACTIVE_HIGH>;
+   };
+
+   led-1 {
+   label = "icnova_a20_adb4006:red:usr";
+   gpios = <&pio 7 20 GPIO_ACTIVE_HIGH>;
+   linux,default-trigger = "heartbeat";
+   };
+   };
+};
+
+&ahci {
+   target-supply 

[PATCH v1 10/14] spi: mpc8xxx: Add support for SPI on mpc832x

2023-04-06 Thread Christophe Leroy
On mpc832x, SPI can be either handled by CPU or QE.
In order to work in CPU mode, bit 17 of SPMODE has to
be set to 1, that bit is called OP.

Also, data is located at a different place than the one expected
by the driver today. In 8 bits mode with REV set, data to be
transmitted is located in the most significant byte while
received data is located in second byte. So perform the
necessary shifts.

In order to differentiate with other CPUs, a new compatible is
added for mpc832x: fsl,mpc832x-spi

Signed-off-by: Christophe Leroy 
Cc: Rasmus Villemoes 
---
 arch/powerpc/include/asm/mpc8xxx_spi.h |  1 +
 drivers/spi/mpc8xxx_spi.c  | 13 +
 2 files changed, 14 insertions(+)

diff --git a/arch/powerpc/include/asm/mpc8xxx_spi.h 
b/arch/powerpc/include/asm/mpc8xxx_spi.h
index 83cfe23b4e..8e9411aefb 100644
--- a/arch/powerpc/include/asm/mpc8xxx_spi.h
+++ b/arch/powerpc/include/asm/mpc8xxx_spi.h
@@ -12,6 +12,7 @@
 
 #if defined(CONFIG_ARCH_MPC8308) || \
defined(CONFIG_ARCH_MPC8313) || \
+   defined(CONFIG_ARCH_MPC832X) || \
defined(CONFIG_ARCH_MPC834X) || \
defined(CONFIG_ARCH_MPC837X)
 
diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
index 6869d60d97..78892173dc 100644
--- a/drivers/spi/mpc8xxx_spi.c
+++ b/drivers/spi/mpc8xxx_spi.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 enum {
SPI_EV_NE = BIT(31 - 22),   /* Receiver Not Empty */
@@ -30,6 +31,7 @@ enum {
SPI_MODE_REV   = BIT(31 - 5),   /* Reverse mode - MSB first */
SPI_MODE_MS= BIT(31 - 6),   /* Always master */
SPI_MODE_EN= BIT(31 - 7),   /* Enable interface */
+   SPI_MODE_OP= BIT(31 - 17),  /* CPU Mode, QE otherwise */
 
SPI_MODE_LEN_MASK = 0xf0,
SPI_MODE_LEN_SHIFT = 20,
@@ -89,6 +91,9 @@ static int mpc8xxx_spi_probe(struct udevice *dev)
 */
out_be32(&priv->spi->mode, SPI_MODE_REV | SPI_MODE_MS);
 
+   if (dev_get_driver_data(dev) == SOC_MPC832X)
+   setbits_be32(&priv->spi->mode, SPI_MODE_OP);
+
/* set len to 8 bits */
setbits_be32(&spi->mode, (8 - 1) << SPI_MODE_LEN_SHIFT);
 
@@ -130,6 +135,7 @@ static int mpc8xxx_spi_xfer(struct udevice *dev, uint 
bitlen,
u32 tmpdin = 0, tmpdout = 0, n;
const u8 *cout = dout;
u8 *cin = din;
+   ulong type = dev_get_driver_data(bus);
 
debug("%s: slave %s:%u dout %08X din %08X bitlen %u\n", __func__,
  bus->name, plat->cs, (uint)dout, (uint)din, bitlen);
@@ -157,6 +163,9 @@ static int mpc8xxx_spi_xfer(struct udevice *dev, uint 
bitlen,
if (cout)
tmpdout = *cout++;
 
+   if (type == SOC_MPC832X)
+   tmpdout <<= 24;
+
/* Write the data out */
out_be32(&spi->tx, tmpdout);
 
@@ -179,6 +188,9 @@ static int mpc8xxx_spi_xfer(struct udevice *dev, uint 
bitlen,
tmpdin = in_be32(&spi->rx);
setbits_be32(&spi->event, SPI_EV_NE);
 
+   if (type == SOC_MPC832X)
+   tmpdin >>= 16;
+
if (cin)
*cin++ = tmpdin;
 
@@ -271,6 +283,7 @@ static const struct dm_spi_ops mpc8xxx_spi_ops = {
 
 static const struct udevice_id mpc8xxx_spi_ids[] = {
{ .compatible = "fsl,spi" },
+   { .compatible = "fsl,mpc832x-spi", .data = SOC_MPC832X },
{ }
 };
 
-- 
2.39.2



[PATCH v1 12/14] board: cssi: Refactor EEPROM read

2023-04-06 Thread Christophe Leroy
On cmpc885 board, the ethernet addresses are stored in an
EEPROM that is accessed through SPI.

A 3 bytes command is sent to the chip then the content
gets read. At the time being a single block access is
performed, ignoring the first 3 bytes read.

Reword the SPI transfer to first send 3 bytes then
receive the content of the EEPROM so that there don't be
3 dummy bytes at the beginning of the buffer.

And move the function into common.c so that it can be
reused by the board that will be added in a future patch.

Signed-off-by: Christophe Leroy 
---
 board/cssi/cmpc885/cmpc885.c | 35 ---
 board/cssi/common/common.c   | 35 +++
 board/cssi/common/common.h   |  1 +
 3 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/board/cssi/cmpc885/cmpc885.c b/board/cssi/cmpc885/cmpc885.c
index 689d573075..8f67f9fc33 100644
--- a/board/cssi/cmpc885/cmpc885.c
+++ b/board/cssi/cmpc885/cmpc885.c
@@ -147,55 +147,28 @@ int checkboard(void)
return 0;
 }
 
-#define SPI_EEPROM_READ0x03
 #define MAX_SPI_BYTES  0x20
 
-#define EE_OFF_MAC10x13
-#define EE_OFF_MAC20x19
+#define EE_OFF_MAC10x10
+#define EE_OFF_MAC20x16
 
 /* Reads MAC addresses from SPI EEPROM */
 static int setup_mac(void)
 {
-   struct udevice *eeprom;
-   struct spi_slave *slave;
-   char name[30], *str;
uchar din[MAX_SPI_BYTES];
-   uchar dout[MAX_SPI_BYTES] = {SPI_EEPROM_READ, 0, 0};
-   int bitlen = 256, cs = 0, mode = 0, bus = 0, ret;
+   int ret;
unsigned long ident = 0x08005120;
 
-   snprintf(name, sizeof(name), "generic_%d:%d", bus, cs);
-
-   str = strdup(name);
-   if (!str)
-   return -1;
-
-   ret = uclass_get_device(UCLASS_SPI, 0, &eeprom);
-   if (ret) {
-   printf("Could not enable Serial Peripheral Interface (SPI).\n");
-   return -1;
-   }
-
-   ret = _spi_get_bus_and_cs(bus, cs, 100, mode, "spi_generic_drv", 
str, &eeprom, &slave);
+   ret = read_eeprom(din, sizeof(din));
if (ret)
return ret;
 
-   ret = spi_claim_bus(slave);
-
-   ret = spi_xfer(slave, bitlen, dout, din, SPI_XFER_BEGIN | SPI_XFER_END);
-   if (ret) {
-   printf("Error %d during SPI transaction\n", ret);
-   return ret;
-   }
-
if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0)
eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
 
if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
 
-   spi_release_bus(slave);
-
return 0;
 }
 
diff --git a/board/cssi/common/common.c b/board/cssi/common/common.c
index 71b35cc692..de68e23fcd 100644
--- a/board/cssi/common/common.c
+++ b/board/cssi/common/common.c
@@ -8,7 +8,11 @@
  * Common specific routines for the CS Group boards
  */
 
+#include 
 #include 
+#include 
+
+#define SPI_EEPROM_READ0x03
 
 static int fdt_set_node_and_value(void *blob, char *node, const char *prop,
  void *var, int size)
@@ -60,3 +64,34 @@ void ft_cleanup(void *blob, unsigned long id, const char 
*prop, const char *comp
 
fdt_set_node_and_value(blob, "/", prop, &id, sizeof(uint32_t));
 }
+
+int read_eeprom(u8 *din, int len)
+{
+   struct udevice *eeprom;
+   struct spi_slave *slave;
+   uchar dout[3] = {SPI_EEPROM_READ, 0, 0};
+   int ret;
+
+   ret = uclass_get_device(UCLASS_SPI, 0, &eeprom);
+   if (ret)
+   return ret;
+
+   ret = _spi_get_bus_and_cs(0, 0, 100, 0, "spi_generic_drv",
+ "generic_0:0", &eeprom, &slave);
+   if (ret)
+   return ret;
+
+   ret = spi_claim_bus(slave);
+
+   ret = spi_xfer(slave, sizeof(dout) << 3, dout, NULL, SPI_XFER_BEGIN);
+   if (ret)
+   return ret;
+
+   ret = spi_xfer(slave, len << 3, NULL, din, SPI_XFER_END);
+   if (ret)
+   return ret;
+
+   spi_release_bus(slave);
+
+   return 0;
+}
diff --git a/board/cssi/common/common.h b/board/cssi/common/common.h
index 16852b6076..9660898cc9 100644
--- a/board/cssi/common/common.h
+++ b/board/cssi/common/common.h
@@ -4,5 +4,6 @@
 #define _BOARD_CSSI_COMMON_H
 
 void ft_cleanup(void *blob, unsigned long id, const char *prop, const char 
*compatible);
+int read_eeprom(u8 *din, int len);
 
 #endif /* _BOARD_CSSI_COMMON_H */
-- 
2.39.2



[PATCH v1 14/14] board: cssi: Add CPU board CMPCPRO

2023-04-06 Thread Christophe Leroy
CSSI has another CPU board, similar to the CMPC885 board
that get plugged on the two base boards MCR3000_2G and MIAE.

That CPU board is called CMPCPRO because it has a MPC8321E CPU,
also known as Power QUICC II PRO.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc83xx/Kconfig |   5 +
 arch/powerpc/dts/Makefile|   1 +
 arch/powerpc/dts/cmpcpro.dts | 189 +++
 board/cssi/MAINTAINERS   |   2 +
 board/cssi/cmpcpro/Kconfig   |  26 ++
 board/cssi/cmpcpro/Makefile  |   8 +
 board/cssi/cmpcpro/cmpcpro.c | 404 +++
 board/cssi/cmpcpro/cmpcpro.env   |   8 +
 board/cssi/cmpcpro/nand.c|  43 
 configs/CMPCPRO_defconfig| 209 
 include/configs/cmpcpro.h|  99 
 11 files changed, 994 insertions(+)
 create mode 100644 arch/powerpc/dts/cmpcpro.dts
 create mode 100644 board/cssi/cmpcpro/Kconfig
 create mode 100644 board/cssi/cmpcpro/Makefile
 create mode 100644 board/cssi/cmpcpro/cmpcpro.c
 create mode 100644 board/cssi/cmpcpro/cmpcpro.env
 create mode 100644 board/cssi/cmpcpro/nand.c
 create mode 100644 configs/CMPCPRO_defconfig
 create mode 100644 include/configs/cmpcpro.h

diff --git a/arch/powerpc/cpu/mpc83xx/Kconfig b/arch/powerpc/cpu/mpc83xx/Kconfig
index b695c7e4d8..582e141221 100644
--- a/arch/powerpc/cpu/mpc83xx/Kconfig
+++ b/arch/powerpc/cpu/mpc83xx/Kconfig
@@ -20,6 +20,10 @@ choice
prompt "Target select"
optional
 
+config TARGET_CMPCPRO
+   bool "Support CMPCPRO board from CSSI"
+   select ARCH_MPC832X
+
 config TARGET_MPC837XERDB
bool "Support MPC837XERDB"
select ARCH_MPC837X
@@ -205,5 +209,6 @@ config NEVER_ASSERT_ODT_TO_CPU
 
 source "board/freescale/mpc837xerdb/Kconfig"
 source "board/gdsys/mpc8308/Kconfig"
+source "board/cssi/cmpcpro/Kconfig"
 
 endmenu
diff --git a/arch/powerpc/dts/Makefile b/arch/powerpc/dts/Makefile
index 26b592b85d..bb436f02bc 100644
--- a/arch/powerpc/dts/Makefile
+++ b/arch/powerpc/dts/Makefile
@@ -30,6 +30,7 @@ dtb-$(CONFIG_TARGET_TUXX1) += kmtuxa1.dtb
 dtb-$(CONFIG_TARGET_MCR3000) += mcr3000.dtb
 dtb-$(CONFIG_TARGET_GAZERBEAM) += gazerbeam.dtb
 dtb-$(CONFIG_TARGET_CMPC885) += cmpc885.dtb
+dtb-$(CONFIG_TARGET_CMPCPRO) += cmpcpro.dtb
 
 include $(srctree)/scripts/Makefile.dts
 
diff --git a/arch/powerpc/dts/cmpcpro.dts b/arch/powerpc/dts/cmpcpro.dts
new file mode 100644
index 00..c27d9dba33
--- /dev/null
+++ b/arch/powerpc/dts/cmpcpro.dts
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * CMPC885 Device Tree Source
+ *
+ * Copyright 2020 CS GROUP France
+ *
+ */
+
+/dts-v1/;
+
+#include 
+
+/ {
+   model = "CMPCPRO";
+   compatible = "fsl, cmpc85xx", "fsl,mod85xx", "CMPCPRO", "MPC8321E", 
"fsl,cmpcpro";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   chosen {
+   stdout-path = &serial0;
+   };
+   WDT: watchdog@0 {
+   device_type = "watchdog";
+   compatible = "fsl,pq1-wdt";
+   };
+
+   aliases {
+   ethernet0 = ð0;
+   etehrnet1 = ð1;
+   serial0 = &serial0;
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   PowerPC,8321@0 {
+   device_type = "cpu";
+   reg = <0x0>;
+   d-cache-line-size = <0x20>; // 32 bytes
+   i-cache-line-size = <0x20>; // 32 bytes
+   d-cache-size = <16384>; // L1, 16K
+   i-cache-size = <16384>; // L1, 16K
+   timebase-frequency = <0>;
+   bus-frequency = <0>;
+   clock-frequency = <0>;
+   };
+   };
+
+   memory {
+   device_type = "memory";
+   reg = <0x 0x2000>;
+   };
+
+   soc8321@b000 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   device_type = "soc";
+   compatible = "simple-bus";
+   ranges = <0x0 0xb000 0x0010>;
+   reg = <0xb000 0x0200>;
+   bus-frequency = <0>;
+   pmc: power@b00 {
+   compatible = "fsl,mpc8323-pmc", "fsl,mpc8349-pmc";
+   reg = <0xb00 0x100 0xa00 0x100>;
+   interrupts = <80 0x8>;
+   interrupt-parent = <&ipic>;
+   };
+   serial0: serial@4500 {
+   clocks = <&socclocks MPC83XX_CLK_CSB>;
+   cell-index = <0>;
+   device_type = "serial";
+   compatible = "fsl,ns16550", "ns16550";
+   reg = <0x4500 0x100>;
+   clock-frequency = <0>;
+   interrupts = <9 0x8>;
+   interrupt-parent = <&ipic>;
+   };
+   ipic:pic@700 {

[PATCH v1 11/14] board: cssi: Create dedicated file for common sources

2023-04-06 Thread Christophe Leroy
In preparation of the new cssi board called cmpcpro which
we be introduce in a future patch, move common
functions into a dedicated file in a common directory.

Signed-off-by: Christophe Leroy 
---
 board/cssi/cmpc885/Makefile  |  2 +-
 board/cssi/cmpc885/cmpc885.c | 54 ++-
 board/cssi/common/common.c   | 62 
 board/cssi/common/common.h   |  8 +
 4 files changed, 73 insertions(+), 53 deletions(-)
 create mode 100644 board/cssi/common/common.c
 create mode 100644 board/cssi/common/common.h

diff --git a/board/cssi/cmpc885/Makefile b/board/cssi/cmpc885/Makefile
index 6c055097cd..baf9e5ab4f 100644
--- a/board/cssi/cmpc885/Makefile
+++ b/board/cssi/cmpc885/Makefile
@@ -5,6 +5,6 @@
 # Christophe Leroy 
 #
 
-obj-y += cmpc885.o
+obj-y += cmpc885.o ../common/common.o
 obj-y += sdram.o
 obj-$(CONFIG_CMD_NAND) += nand.o
diff --git a/board/cssi/cmpc885/cmpc885.c b/board/cssi/cmpc885/cmpc885.c
index 5233c24aae..689d573075 100644
--- a/board/cssi/cmpc885/cmpc885.c
+++ b/board/cssi/cmpc885/cmpc885.c
@@ -22,9 +22,10 @@
 #include 
 #include 
 #include 
-
 #include 
 
+#include "../common/common.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 #define BOARD_CMPC885  "cmpc885"
@@ -59,57 +60,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define R_RESET_STATUS 0x0400
 #define R_RST_STATUS   0x0004
 
-static int fdt_set_node_and_value(void *blob, char *node, const char *prop,
- void *var, int size)
-{
-   int ret, off;
-
-   off = fdt_path_offset(blob, node);
-
-   if (off < 0) {
-   printf("Cannot find %s node err:%s\n", node, fdt_strerror(off));
-
-   return off;
-   }
-
-   ret = fdt_setprop(blob, off, prop, var, size);
-
-   if (ret < 0)
-   printf("Cannot set %s/%s prop err: %s\n", node, prop, 
fdt_strerror(ret));
-
-   return ret;
-}
-
-/* Checks front/rear id and remove unneeded nodes from the blob */
-static void ft_cleanup(void *blob, uint32_t id, const char *prop, const char 
*compatible)
-{
-   int off;
-
-   off = fdt_node_offset_by_compatible(blob, -1, compatible);
-
-   while (off != -FDT_ERR_NOTFOUND) {
-   const struct fdt_property *ids;
-   int nb_ids, idx;
-   int tmp = -1;
-
-   ids = fdt_get_property(blob, off, prop, &nb_ids);
-
-   for (idx = 0; idx < nb_ids; idx += 4) {
-   if (*((uint32_t *)&ids->data[idx]) == id)
-   break;
-   }
-
-   if (idx >= nb_ids)
-   fdt_del_node(blob, off);
-   else
-   tmp = off;
-
-   off = fdt_node_offset_by_compatible(blob, tmp, compatible);
-   }
-
-   fdt_set_node_and_value(blob, "/", prop, &id, sizeof(uint32_t));
-}
-
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
u8 fav_id, far_id;
diff --git a/board/cssi/common/common.c b/board/cssi/common/common.c
new file mode 100644
index 00..71b35cc692
--- /dev/null
+++ b/board/cssi/common/common.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2010-2020 CS Group
+ * Charles Frey 
+ * Florent Trinh Thai 
+ * Christophe Leroy 
+ *
+ * Common specific routines for the CS Group boards
+ */
+
+#include 
+
+static int fdt_set_node_and_value(void *blob, char *node, const char *prop,
+ void *var, int size)
+{
+   int ret, off;
+
+   off = fdt_path_offset(blob, node);
+
+   if (off < 0) {
+   printf("Cannot find %s node err:%s\n", node, fdt_strerror(off));
+
+   return off;
+   }
+
+   ret = fdt_setprop(blob, off, prop, var, size);
+
+   if (ret < 0)
+   printf("Cannot set %s/%s prop err: %s\n", node, prop, 
fdt_strerror(ret));
+
+   return ret;
+}
+
+/* Checks front/rear id and remove unneeded nodes from the blob */
+void ft_cleanup(void *blob, unsigned long id, const char *prop, const char 
*compatible)
+{
+   int off;
+
+   off = fdt_node_offset_by_compatible(blob, -1, compatible);
+
+   while (off != -FDT_ERR_NOTFOUND) {
+   const struct fdt_property *ids;
+   int nb_ids, idx;
+   int tmp = -1;
+
+   ids = fdt_get_property(blob, off, prop, &nb_ids);
+
+   for (idx = 0; idx < nb_ids; idx += 4) {
+   if (*((uint32_t *)&ids->data[idx]) == id)
+   break;
+   }
+
+   if (idx >= nb_ids)
+   fdt_del_node(blob, off);
+   else
+   tmp = off;
+
+   off = fdt_node_offset_by_compatible(blob, tmp, compatible);
+   }
+
+   fdt_set_node_and_value(blob, "/", prop, &id, sizeof(uint32_t));
+}
diff --git a/board/cssi/common/common.h b/board/cssi/common/common.h
new file mode 100644
index 00..16852b6076
--- /dev/null
+++

[PATCH v1 09/14] gpio: Add QUICC Engine GPIOs driver

2023-04-06 Thread Christophe Leroy
The mpc832x has GPIOs handled by the QUICC Engine.
The registers are different from the one for the
non QE mpc83xx GPIOs.

Implement a GPIO driver for those.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/arch-mpc83xx/gpio.h |   5 +
 drivers/gpio/Kconfig |  18 ++
 drivers/gpio/Makefile|   1 +
 drivers/gpio/qe_gpio.c   | 170 +++
 4 files changed, 194 insertions(+)
 create mode 100644 drivers/gpio/qe_gpio.c

diff --git a/arch/powerpc/include/asm/arch-mpc83xx/gpio.h 
b/arch/powerpc/include/asm/arch-mpc83xx/gpio.h
index 19c2506c9b..df95d2238f 100644
--- a/arch/powerpc/include/asm/arch-mpc83xx/gpio.h
+++ b/arch/powerpc/include/asm/arch-mpc83xx/gpio.h
@@ -22,6 +22,11 @@ struct mpc8xxx_gpio_plat {
uint ngpios;
 };
 
+struct qe_gpio_plat {
+   ulong addr;
+   unsigned long size;
+};
+
 #ifndef DM_GPIO
 void mpc83xx_gpio_init_f(void);
 void mpc83xx_gpio_init_r(void);
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7d5ddbdee0..9bf6e428de 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -547,6 +547,24 @@ config MPC8XXX_GPIO
  value setting, the open-drain feature, which can configure individual
  GPIOs to work as open-drain outputs, is supported.
 
+config QE_GPIO
+   bool "Freescale QUICC ENGINE GPIO driver"
+   depends on DM_GPIO
+   depends on QE
+   help
+ This driver supports the QUICC Engine GPIOs of MPC83XX CPUs.
+ Each GPIO bank is identified by its own entry in the device tree,
+ i.e.
+
+ qe_pio_a: gpio-controller@1400 {
+   compatible = "fsl,mpc8323-qe-pario-bank";
+   reg = <0x1400 0x18>;
+   gpio-controller;
+   #gpio-cells = <2>;
+ };
+
+ Each bank has 32 GPIOs.
+
 config MPC8XX_GPIO
bool "Freescale MPC8XX GPIO driver"
depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 1e81e36962..64a36c472e 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_TEGRA186_GPIO)   += tegra186_gpio.o
 obj-$(CONFIG_DA8XX_GPIO)   += da8xx_gpio.o
 obj-$(CONFIG_ALTERA_PIO)   += altera_pio.o
 obj-$(CONFIG_MPC8XXX_GPIO) += mpc8xxx_gpio.o
+obj-$(CONFIG_QE_GPIO)  += qe_gpio.o
 obj-$(CONFIG_MPC8XX_GPIO)  += mpc8xx_gpio.o
 obj-$(CONFIG_MPC83XX_SPISEL_BOOT)  += mpc83xx_spisel_boot.o
 obj-$(CONFIG_SH_GPIO_PFC)  += sh_pfc.o
diff --git a/drivers/gpio/qe_gpio.c b/drivers/gpio/qe_gpio.c
new file mode 100644
index 00..16e8d1eae6
--- /dev/null
+++ b/drivers/gpio/qe_gpio.c
@@ -0,0 +1,170 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 CR GROUP France
+ * Christophe Leroy 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define QE_DIR_NONE0
+#define QE_DIR_OUT 1
+#define QE_DIR_IN  2
+#define QE_DIR_IN_OUT  3
+
+struct qe_gpio_data {
+   /* The bank's register base in memory */
+   struct gpio_n __iomem *base;
+   /* The address of the registers; used to identify the bank */
+   phys_addr_t addr;
+};
+
+static inline u32 gpio_mask(uint gpio)
+{
+   return 1U << (31 - (gpio));
+}
+
+static inline u32 gpio_mask2(uint gpio)
+{
+   return 1U << (30 - ((gpio & 15) << 1));
+}
+
+static int qe_gpio_direction_input(struct udevice *dev, uint gpio)
+{
+   struct qe_gpio_data *data = dev_get_priv(dev);
+   struct gpio_n __iomem *base = data->base;
+   u32 mask2 = gpio_mask2(gpio);
+
+   if (gpio < 16)
+   clrsetbits_be32(&base->dir1, mask2 * QE_DIR_OUT, mask2 * 
QE_DIR_IN);
+   else
+   clrsetbits_be32(&base->dir2, mask2 * QE_DIR_OUT, mask2 * 
QE_DIR_IN);
+
+   return 0;
+}
+
+static int qe_gpio_set_value(struct udevice *dev, uint gpio, int value)
+{
+   struct qe_gpio_data *data = dev_get_priv(dev);
+   struct gpio_n __iomem *base = data->base;
+   u32 mask = gpio_mask(gpio);
+   u32 mask2 = gpio_mask2(gpio);
+
+   if (gpio < 16)
+   clrsetbits_be32(&base->dir1, mask2 * QE_DIR_IN, mask2 * 
QE_DIR_OUT);
+   else
+   clrsetbits_be32(&base->dir2, mask2 * QE_DIR_IN, mask2 * 
QE_DIR_OUT);
+
+   if (value)
+   setbits_be32(&base->pdat, mask);
+   else
+   clrbits_be32(&base->pdat, mask);
+
+   return 0;
+}
+
+static int qe_gpio_get_value(struct udevice *dev, uint gpio)
+{
+   struct qe_gpio_data *data = dev_get_priv(dev);
+   struct gpio_n __iomem *base = data->base;
+   u32 mask = gpio_mask(gpio);
+
+   return !!(in_be32(&base->pdat) & mask);
+}
+
+static int qe_gpio_get_function(struct udevice *dev, uint gpio)
+{
+   struct qe_gpio_data *data = dev_get_priv(dev);
+   struct gpio_n __iomem *base = data->base;
+   u32 mask2 = gpio_mask2(gpio);
+   int dir;
+
+   if (gpio < 16)
+   dir = in_be32(&base->dir1

[PATCH v1 13/14] board: cssi: Move all mother board code into common.c

2023-04-06 Thread Christophe Leroy
All the code used to manage the mother boards will be
common to soon to come CPU board.

Move all that code into common.c

Signed-off-by: Christophe Leroy 
---
 board/cssi/cmpc885/cmpc885.c | 152 +--
 board/cssi/common/common.c   | 124 +++-
 board/cssi/common/common.h   |   8 +-
 include/configs/cmpc885.h|   6 ++
 4 files changed, 157 insertions(+), 133 deletions(-)

diff --git a/board/cssi/cmpc885/cmpc885.c b/board/cssi/cmpc885/cmpc885.c
index 8f67f9fc33..540b9d3c78 100644
--- a/board/cssi/cmpc885/cmpc885.c
+++ b/board/cssi/cmpc885/cmpc885.c
@@ -28,33 +28,15 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define BOARD_CMPC885  "cmpc885"
-#define BOARD_MCR3000_2G   "mcr3k_2g"
-#define BOARD_VGOIP"vgoip"
-#define BOARD_MIAE "miae"
-
-#define TYPE_MCR   0x22
-#define TYPE_MIAE  0x23
-
-#define FAR_CASRSA 2
-#define FAR_VGOIP  4
-#define FAV_CLA7
-#define FAV_SRSA   8
-
 #define ADDR_CPLD_R_RESET  ((unsigned short __iomem 
*)CONFIG_CPLD_BASE)
 #define ADDR_CPLD_R_ETAT   ((unsigned short __iomem 
*)(CONFIG_CPLD_BASE + 2))
 #define ADDR_CPLD_R_TYPE   ((unsigned char  __iomem 
*)(CONFIG_CPLD_BASE + 3))
 
-#define ADDR_FPGA_R_BASE   ((unsigned char  __iomem 
*)CONFIG_FPGA_BASE)
-#define ADDR_FPGA_R_ALARMES_IN ((unsigned char  __iomem 
*)CONFIG_FPGA_BASE + 0x31)
-#define ADDR_FPGA_R_FAV((unsigned char  __iomem 
*)CONFIG_FPGA_BASE + 0x44)
-
 #define PATH_PHY2  "/soc@ff00/mdio@e00/ethernet-phy@2"
 #define PATH_PHY3  "/soc@ff00/mdio@e00/ethernet-phy@3"
 #define PATH_ETH1  "/soc@ff00/ethernet@1e00"
 #define FIBER_PHY PATH_PHY2
 
-#define FPGA_R_ACQ_AL_FAV  0x04
 #define R_ETAT_PRES_BASE   0x0040
 
 #define R_RESET_STATUS 0x0400
@@ -62,8 +44,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
-   u8 fav_id, far_id;
-
const char *sync = "receive";
 
ft_cpu_setup(blob, bd);
@@ -87,32 +67,19 @@ int ft_board_setup(void *blob, struct bd_info *bd)
do_fixup_by_path(blob, "/localbus/e1", "rising-edge-sync-pulse", sync, 
strlen(sync), 1);
 
/* MIAE only */
-   if (!(in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) || 
in_8(ADDR_FPGA_R_BASE) != TYPE_MIAE)
+   if (!(in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE))
return 0;
 
-   far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5;
-   ft_cleanup(blob, (u32)far_id, "far-id", "cs,mia-far");
-
-   /*
-* special case, with CASRSA (far_id: 2)
-* FAV-SRSA register itself as FAV-CLA
-*/
-   fav_id = in_8(ADDR_FPGA_R_BASE + 0x44) >> 5;
-
-   if (far_id == FAR_CASRSA && fav_id == FAV_CLA)
-   fav_id = FAV_SRSA;
-
-   ft_cleanup(blob, (u32)fav_id, "fav-id", "cs,mia-fav");
-
-   if (far_id == FAR_CASRSA) {
-   /* switch to phy3 with gpio, we'll only use phy3 */
-   immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
-   cpm8xx_t __iomem *cp = (cpm8xx_t __iomem *)&immr->im_cpm;
+   return ft_board_setup_common(blob);
+}
 
-   setbits_be32(&cp->cp_pedat, 0x2000);
-   }
+void ft_board_setup_phy3(void)
+{
+   /* switch to phy3 with gpio, we'll only use phy3 */
+   immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
+   cpm8xx_t __iomem *cp = (cpm8xx_t __iomem *)&immr->im_cpm;
 
-   return 0;
+   setbits_be32(&cp->cp_pedat, 0x2000);
 }
 
 int checkboard(void)
@@ -120,30 +87,11 @@ int checkboard(void)
serial_puts("Board: ");
 
/* Is a motherboard present ? */
-   if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE) {
-   switch (in_8(ADDR_FPGA_R_BASE)) {
-   int far_id;
-   case TYPE_MCR:
-   printf("MCR3000_2G (CS GROUP)\n");
-   break;
-   case TYPE_MIAE:
-   far_id = in_8(ADDR_FPGA_R_BASE + 0x43) >> 5;
-
-   if (far_id == FAR_VGOIP)
-   printf("VGoIP (CS GROUP)\n");
-   else
-   printf("MIAE (CS GROUP)\n");
-
-   break;
-   default:
-   printf("Unknown\n");
-   for (;;)
-   ;
-   break;
-   }
-   } else {
-   printf("CMPC885 (CS GROUP)\n");
-   }
+   if (in_be16(ADDR_CPLD_R_ETAT) & R_ETAT_PRES_BASE)
+   return checkboard_common();
+
+   printf("CMPC885 (CS GROUP)\n");
+
return 0;
 }
 
@@ -174,57 +122,12 @@ static int setup_mac(void)
 
 int misc_init_r(void)
 {
-   u8 val, tmp, far_id;
-   int count = 3;
-
-   val = in_8(ADDR_FPGA_R_BASE);
-
/* Verify mother

[PATCH v1 02/14] watchdog: mpc8xx: Rename it mpc8xxx

2023-04-06 Thread Christophe Leroy
mpc8xx, mpc83xx and mpc86xx have similar watchdog with almost same
memory registers.

Rename it mpc8xxx which is the generic name used for drivers supporting
several mpc families.

The driver will be made more generic in following patch.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig  |  2 +-
 drivers/watchdog/Kconfig  |  6 ++---
 drivers/watchdog/Makefile |  2 +-
 .../watchdog/{mpc8xx_wdt.c => mpc8xxx_wdt.c}  | 24 +--
 4 files changed, 17 insertions(+), 17 deletions(-)
 rename drivers/watchdog/{mpc8xx_wdt.c => mpc8xxx_wdt.c} (72%)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index bee59c3bea..f20d58b4de 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -31,7 +31,7 @@ config MPC8xx
select CREATE_ARCH_SYMLINK
select BOARD_EARLY_INIT_F
imply CMD_REGINFO
-   imply WDT_MPC8xx
+   imply WDT_MPC8xxx
 
 endchoice
 
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b5ac8f7f50..f6554d5c93 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -184,12 +184,12 @@ config WDT_MESON_GXBB
  Select this to enable Meson watchdog timer,
  which can be found on some Amlogic platforms.
 
-config WDT_MPC8xx
-   bool "MPC8xx watchdog timer support"
+config WDT_MPC8xxx
+   bool "MPC8xxx watchdog timer support"
depends on WDT && MPC8xx
select HW_WATCHDOG
help
- Select this to enable mpc8xx watchdog timer
+ Select this to enable mpc8xxx watchdog timer
 
 config WDT_MT7620
bool "MediaTek MT7620 watchdog timer support"
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 446d961d7d..aba1df285d 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o
 obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o
 obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o
 obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o
-obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
+obj-$(CONFIG_WDT_MPC8xxx) += mpc8xxx_wdt.o
 obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o
 obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
 obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
diff --git a/drivers/watchdog/mpc8xx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
similarity index 72%
rename from drivers/watchdog/mpc8xx_wdt.c
rename to drivers/watchdog/mpc8xxx_wdt.c
index c8b104d8f5..ffca3ec877 100644
--- a/drivers/watchdog/mpc8xx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -19,7 +19,7 @@ void hw_watchdog_reset(void)
out_be16(&immap->im_siu_conf.sc_swsr, 0xaa39);  /* write magic2 */
 }
 
-static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
+static int mpc8xxx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
 {
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
u32 val = CONFIG_SYS_SYPCR;
@@ -38,7 +38,7 @@ static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, 
ulong flags)
 
 }
 
-static int mpc8xx_wdt_stop(struct udevice *dev)
+static int mpc8xxx_wdt_stop(struct udevice *dev)
 {
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
 
@@ -49,27 +49,27 @@ static int mpc8xx_wdt_stop(struct udevice *dev)
return 0;
 }
 
-static int mpc8xx_wdt_reset(struct udevice *dev)
+static int mpc8xxx_wdt_reset(struct udevice *dev)
 {
hw_watchdog_reset();
 
return 0;
 }
 
-static const struct wdt_ops mpc8xx_wdt_ops = {
-   .start = mpc8xx_wdt_start,
-   .reset = mpc8xx_wdt_reset,
-   .stop = mpc8xx_wdt_stop,
+static const struct wdt_ops mpc8xxx_wdt_ops = {
+   .start = mpc8xxx_wdt_start,
+   .reset = mpc8xxx_wdt_reset,
+   .stop = mpc8xxx_wdt_stop,
 };
 
-static const struct udevice_id mpc8xx_wdt_ids[] = {
+static const struct udevice_id mpc8xxx_wdt_ids[] = {
{ .compatible = "fsl,pq1-wdt" },
{}
 };
 
-U_BOOT_DRIVER(wdt_mpc8xx) = {
-   .name = "wdt_mpc8xx",
+U_BOOT_DRIVER(wdt_mpc8xxx) = {
+   .name = "wdt_mpc8xxx",
.id = UCLASS_WDT,
-   .of_match = mpc8xx_wdt_ids,
-   .ops = &mpc8xx_wdt_ops,
+   .of_match = mpc8xxx_wdt_ids,
+   .ops = &mpc8xxx_wdt_ops,
 };
-- 
2.39.2



[PATCH v1 04/14] watchdog: mpc8xxx: Add support for mpc83xx

2023-04-06 Thread Christophe Leroy
Introduce a new compatible "fsl,pq2pro-wdt"
On mpc83xx, the prescaling factor is 0x1.

Don't write the watchdog configuration register in
start.S as it can be written only once.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc83xx/cpu.c   | 2 +-
 arch/powerpc/cpu/mpc83xx/start.S | 2 ++
 drivers/watchdog/Kconfig | 2 +-
 drivers/watchdog/mpc8xxx_wdt.c   | 1 +
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/cpu/mpc83xx/cpu.c b/arch/powerpc/cpu/mpc83xx/cpu.c
index a6c063556e..f6ffe295b8 100644
--- a/arch/powerpc/cpu/mpc83xx/cpu.c
+++ b/arch/powerpc/cpu/mpc83xx/cpu.c
@@ -165,7 +165,7 @@ unsigned long get_tbclk(void)
 }
 #endif
 
-#if defined(CONFIG_WATCHDOG)
+#if defined(CONFIG_WATCHDOG) && !defined(CONFIG_WDT)
 void watchdog_reset (void)
 {
int re_enable = disable_interrupts();
diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index e3878e431f..4329b173db 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -483,6 +483,7 @@ init_e300_core: /* time t 10 */
 
 
lis r3, CONFIG_SYS_IMMR@h
+#ifndef CONFIG_WDT_MPC8xxx
 #if defined(CONFIG_WATCHDOG)
/* Initialise the Watchdog values and reset it (if req) */
/*--*/
@@ -508,6 +509,7 @@ init_e300_core: /* time t 10 */
stw r4, SWCRR(r3)
 1:
 #endif /* CONFIG_WATCHDOG */
+#endif
 
 #if defined(CONFIG_MASK_AER_AO)
/* Write the Arbiter Event Enable to mask Address Only traps. */
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index f7fbb28d80..f7767596e1 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -186,7 +186,7 @@ config WDT_MESON_GXBB
 
 config WDT_MPC8xxx
bool "MPC8xxx watchdog timer support"
-   depends on WDT && MPC8xx
+   depends on WDT && (MPC8xx || MPC83xx)
help
  Select this to enable mpc8xxx watchdog timer
 
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 9a29938fac..f28636ca90 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -98,6 +98,7 @@ static const struct wdt_ops mpc8xxx_wdt_ops = {
 
 static const struct udevice_id mpc8xxx_wdt_ids[] = {
{ .compatible = "fsl,pq1-wdt", .data = 0x800 },
+   { .compatible = "fsl,pq2pro-wdt", .data = 0x1 },
{}
 };
 
-- 
2.39.2



[PATCH v1 08/14] clk: mpc83xx: Fix clocks for mpc832x

2023-04-06 Thread Christophe Leroy
gd->arch.sdhc_clk only exists when CONFIG_FSL_ESDHC is set,
so enclose it inside ifdefs.

gd->arch.qe_clk and gd->arch.brg_clk must be populated when
CONFIG_QE is set.

Signed-off-by: Christophe Leroy 
---
 drivers/clk/mpc83xx_clk.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/clk/mpc83xx_clk.c b/drivers/clk/mpc83xx_clk.c
index 0255ccaf8a..cc734450ef 100644
--- a/drivers/clk/mpc83xx_clk.c
+++ b/drivers/clk/mpc83xx_clk.c
@@ -346,8 +346,10 @@ static int mpc83xx_clk_probe(struct udevice *dev)
 
type = dev_get_driver_data(dev);
 
+#ifdef CONFIG_FSL_ESDHC
if (mpc83xx_has_sdhc(type))
gd->arch.sdhc_clk = priv->speed[MPC83XX_CLK_SDHC];
+#endif
 
gd->arch.core_clk = priv->speed[MPC83XX_CLK_CORE];
gd->arch.i2c1_clk = priv->speed[MPC83XX_CLK_I2C1];
@@ -362,6 +364,11 @@ static int mpc83xx_clk_probe(struct udevice *dev)
gd->cpu_clk = priv->speed[MPC83XX_CLK_CORE];
gd->bus_clk = priv->speed[MPC83XX_CLK_CSB];
 
+#ifdef CONFIG_QE
+   gd->arch.qe_clk = priv->speed[MPC83XX_CLK_QE];
+   gd->arch.brg_clk = priv->speed[MPC83XX_CLK_BRG];
+#endif
+
return 0;
 }
 
-- 
2.39.2



[PATCH v1 06/14] powerpc: mpc83xx: Fix soc.h

2023-04-06 Thread Christophe Leroy
There are helpers included in soc.h

Declare them static inline so that soc.h can be
included in several places.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/arch-mpc83xx/soc.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/arch-mpc83xx/soc.h 
b/arch/powerpc/include/asm/arch-mpc83xx/soc.h
index 39bf7d5a7f..ce54f9bebb 100644
--- a/arch/powerpc/include/asm/arch-mpc83xx/soc.h
+++ b/arch/powerpc/include/asm/arch-mpc83xx/soc.h
@@ -18,14 +18,14 @@ enum soc_type {
SOC_MPC8379,
 };
 
-bool mpc83xx_has_sdhc(int type)
+static inline bool mpc83xx_has_sdhc(int type)
 {
return (type == SOC_MPC8308) ||
   (type == SOC_MPC8309) ||
   (type == SOC_MPC8379);
 }
 
-bool mpc83xx_has_tsec(int type)
+static inline bool mpc83xx_has_tsec(int type)
 {
return (type == SOC_MPC8308) ||
   (type == SOC_MPC8313) ||
@@ -34,37 +34,37 @@ bool mpc83xx_has_tsec(int type)
   (type == SOC_MPC8379);
 }
 
-bool mpc83xx_has_pcie1(int type)
+static inline bool mpc83xx_has_pcie1(int type)
 {
return (type == SOC_MPC8308) ||
   (type == SOC_MPC8315) ||
   (type == SOC_MPC8379);
 }
 
-bool mpc83xx_has_pcie2(int type)
+static inline bool mpc83xx_has_pcie2(int type)
 {
return (type == SOC_MPC8315) ||
   (type == SOC_MPC8379);
 }
 
-bool mpc83xx_has_sata(int type)
+static inline bool mpc83xx_has_sata(int type)
 {
return (type == SOC_MPC8315) ||
   (type == SOC_MPC8379);
 }
 
-bool mpc83xx_has_pci(int type)
+static inline bool mpc83xx_has_pci(int type)
 {
return type != SOC_MPC8308;
 }
 
-bool mpc83xx_has_second_i2c(int type)
+static inline bool mpc83xx_has_second_i2c(int type)
 {
return (type != SOC_MPC8315) &&
   (type != SOC_MPC832X);
 }
 
-bool mpc83xx_has_quicc_engine(int type)
+static inline bool mpc83xx_has_quicc_engine(int type)
 {
return (type == SOC_MPC8309) ||
   (type == SOC_MPC832X) ||
-- 
2.39.2



[PATCH v1 03/14] watchdog: mpc8xxx: Make it generic

2023-04-06 Thread Christophe Leroy
mpc8xx, mpc83xx and mpc86xx have similar watchdog with almost same
memory registers.

Refactor the driver to get the register addresses from the
device tree and use the compatible to know the prescale factor.

Calculate the watchdog setup value from the provided timeout.

Don't declare it anymore as an HW_WATCHDOG, u-boot will start
servicing the watchdog early enough.

On mpc8xx the watchdog configuration register is also used for
configuring the bus monitor. So add it as an option to the watchdog
when it is mpc8xx. When watchdog is not selected, leave the
configuration of the initial SYPCR from Kconfig.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc8xx/Kconfig|  3 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c |  5 +--
 arch/powerpc/dts/cmpc885.dts   | 12 ++---
 arch/powerpc/dts/mcr3000.dts   | 20 -
 board/cssi/mcr3000/mcr3000.c   | 14 --
 configs/CMPC885_defconfig  |  2 +-
 configs/MCR3000_defconfig  |  3 +-
 drivers/watchdog/Kconfig   | 18 +++-
 drivers/watchdog/mpc8xxx_wdt.c | 72 ++
 9 files changed, 102 insertions(+), 47 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8xx/Kconfig b/arch/powerpc/cpu/mpc8xx/Kconfig
index a705014512..bfd903bc10 100644
--- a/arch/powerpc/cpu/mpc8xx/Kconfig
+++ b/arch/powerpc/cpu/mpc8xx/Kconfig
@@ -48,7 +48,8 @@ config SYS_SIUMCR
  SIU Module Configuration (11-6)
 
 config SYS_SYPCR
-   hex "SYPCR register"
+   hex "SYPCR register" if !WDT_MPC8xxx
+   default 0
help
  System Protection Control (11-9)
 
diff --git a/arch/powerpc/cpu/mpc8xx/cpu_init.c 
b/arch/powerpc/cpu/mpc8xx/cpu_init.c
index 86b08a6174..feef792ee7 100644
--- a/arch/powerpc/cpu/mpc8xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc8xx/cpu_init.c
@@ -26,10 +26,9 @@ void cpu_init_f(immap_t __iomem *immr)
 
/* SYPCR - contains watchdog control (11-9) */
 
-#ifndef CONFIG_HW_WATCHDOG
/* deactivate watchdog if not enabled in config */
-   out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & ~SYPCR_SWE);
-#endif
+   if (!IS_ENABLED(CONFIG_WDT_MPC8xxx))
+   out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & 
~SYPCR_SWE);
 
schedule();
 
diff --git a/arch/powerpc/dts/cmpc885.dts b/arch/powerpc/dts/cmpc885.dts
index adda0f3e9d..7b9566a0fa 100644
--- a/arch/powerpc/dts/cmpc885.dts
+++ b/arch/powerpc/dts/cmpc885.dts
@@ -18,11 +18,6 @@
stdout-path = &SERIAL;
};
 
-   WDT: watchdog@0 {
-   device_type = "watchdog";
-   compatible = "fsl,pq1-wdt";
-   };
-
SERIAL: serial {
compatible = "fsl,pq1-smc";
};
@@ -43,6 +38,13 @@
ranges = <0 0xff00 0x4000>;
reg = <0xff00 0x0200>;
 
+   WDT: watchdog@0 {
+   compatible = "fsl,pq1-wdt";
+   reg = <0x0 0x10>;
+   timeout-sec = <2>;
+   hw_margin_ms = <1000>;
+   };
+
CPM1_PIO_B: gpio-controller@ab8 {
#gpio-cells = <2>;
compatible = "fsl,cpm1-pario-bank-b";
diff --git a/arch/powerpc/dts/mcr3000.dts b/arch/powerpc/dts/mcr3000.dts
index 5f32d8a2e5..c4d7737bc6 100644
--- a/arch/powerpc/dts/mcr3000.dts
+++ b/arch/powerpc/dts/mcr3000.dts
@@ -9,9 +9,25 @@
 /dts-v1/;
 
 / {
-   WDT: watchdog@0 {
-   compatible = "fsl,pq1-wdt";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   soc: immr@ff00 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   device-type = "soc";
+   compatible = "simple-bus";
+   ranges = <0 0xff00 0x4000>;
+   reg = <0xff00 0x0200>;
+
+   WDT: watchdog@0 {
+   compatible = "fsl,pq1-wdt";
+   reg = <0x0 0x10>;
+   timeout-sec = <2>;
+   hw_margin_ms = <1000>;
+   };
};
+
SERIAL: smc@0 {
compatible = "fsl,pq1-smc";
};
diff --git a/board/cssi/mcr3000/mcr3000.c b/board/cssi/mcr3000/mcr3000.c
index 7b3ab12bd5..3514f67490 100644
--- a/board/cssi/mcr3000/mcr3000.c
+++ b/board/cssi/mcr3000/mcr3000.c
@@ -138,17 +138,3 @@ int board_early_init_f(void)
 
return 0;
 }
-
-int board_early_init_r(void)
-{
-   struct udevice *watchdog_dev = NULL;
-
-   if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
-   puts("Cannot find watchdog!\n");
-   } else {
-   puts("Enabling watchdog.\n");
-   wdt_start(watchdog_dev, 0x, 0);
-   }
-
-   return 0;
-}
diff --git a/configs/CMPC885_defconfig b/configs/CMPC885_defconfig
index 484a81b8d3..1fe67d02f2 100644
--- a/configs/CMPC885_defconfig
+++ b/configs/CMPC885_defconfig
@@ -11,7 +11,6 @@ CONFIG_TARGET_CMPC885=y
 CONFIG_MPC885=y
 CONFIG_CMD_IMMAP=y
 CON

[PATCH v1 05/14] powerpc: mpc832x: Fix reset word

2023-04-06 Thread Christophe Leroy
According to the reference manual, the Reset Configuration
Word Low Register bits 2-3 must be set to 0b10.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc83xx/hrcw/Kconfig | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/cpu/mpc83xx/hrcw/Kconfig 
b/arch/powerpc/cpu/mpc83xx/hrcw/Kconfig
index b67ccd661d..44f66cd528 100644
--- a/arch/powerpc/cpu/mpc83xx/hrcw/Kconfig
+++ b/arch/powerpc/cpu/mpc83xx/hrcw/Kconfig
@@ -539,8 +539,7 @@ config DDR_MC_CLOCK_MODE
 
 config SYSTEM_PLL_VCO_DIV
int
-   default 0 if ARCH_MPC832X
-   default 2 if ARCH_MPC8313
+   default 2 if ARCH_MPC8313 || ARCH_MPC832X
default 0 if SYSTEM_PLL_VCO_DIV_2 && !ARCH_MPC8360 && !ARCH_MPC837X
default 1 if SYSTEM_PLL_VCO_DIV_4 && !ARCH_MPC8360 && !ARCH_MPC837X
default 2 if SYSTEM_PLL_VCO_DIV_8 && !ARCH_MPC8360 && !ARCH_MPC837X
-- 
2.39.2



[PATCH v1 07/14] powerpc: mpc83xx: Don't activate MMU when not necessary

2023-04-06 Thread Christophe Leroy
At startup, some RAM is needed (for instance for stack) before
DRAM is initialised.

One way to offer such RAM, used by mpc83xx, is to lock some entries
in the cache. To do that, MMU needs to be activated.

On mpc83xx having a QUICC Engine an alternative is to user some
part of from the Multi User RAM, like done on mpc8xx for instance.
For that, the MMU is not needed.

Activating the MMU is problematic because exception vectors are not
setup yet so in case of ISI or DSI that CPU will crash and reboot.

At the time being, MMU is activated regardless.

Only activate it when locking cache entries to provide initial RAM.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc83xx/start.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index 4329b173db..6749263da8 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -215,6 +215,7 @@ in_flash:
 * gt-regs BAT can be reused after board_init_f calls
 * board_early_init_f (EVB only).
 */
+#ifdef CONFIG_SYS_INIT_RAM_LOCK
/* enable address translation */
bl  enable_addr_trans
sync
@@ -222,7 +223,6 @@ in_flash:
/* enable the data cache */
bl  dcache_enable
sync
-#ifdef CONFIG_SYS_INIT_RAM_LOCK
bl  lock_ram_in_cache
sync
 #endif
-- 
2.39.2



[PATCH v1 00/14] Add new CS GROUP CPU board CMPCPRO (v1)

2023-04-06 Thread Christophe Leroy
This series adds support for the last CPU board from
CS GROUP France (previously CSSI).

That CPU board called CMPCPRO has a mpc8321E CPU (Family PQII PRO hence
its name) and can be plugged in place of the CMPC885 board.

In order to support that new board, the following changes are included
in this series:
- Make the mpc8xx watchdog driver more generic for reusing it
with mpc83xx
- Fix various small problems on mpc83xx platform
- Add a GPIO Driver for QE GPIOs
- Add support for mpc832x into mpc83xx SPI driver
- Refactor existing board code that will be shared with new board
- Add the new board

This series is based on today's next tree and has passed CI tests at
https://source.denx.de/u-boot/custodians/u-boot-mpc8xx/-/pipelines/15928

Christophe Leroy (14):
  powerpc: mpc8xx: Migrate to CONFIG_SYS_CLK_FREQ
  watchdog: mpc8xx: Rename it mpc8xxx
  watchdog: mpc8xxx: Make it generic
  watchdog: mpc8xxx: Add support for mpc83xx
  powerpc: mpc832x: Fix reset word
  powerpc: mpc83xx: Fix soc.h
  powerpc: mpc83xx: Don't activate MMU when not necessary
  clk: mpc83xx: Fix clocks for mpc832x
  gpio: Add QUICC Engine GPIOs driver
  spi: mpc8xxx: Add support for SPI on mpc832x
  board: cssi: Create dedicated file for common sources
  board: cssi: Refactor EEPROM read
  board: cssi: Move all mother board code into common.c
  board: cssi: Add CPU board CMPCPRO

 arch/powerpc/Kconfig |   2 +-
 arch/powerpc/cpu/mpc83xx/Kconfig |   5 +
 arch/powerpc/cpu/mpc83xx/cpu.c   |   2 +-
 arch/powerpc/cpu/mpc83xx/hrcw/Kconfig|   3 +-
 arch/powerpc/cpu/mpc83xx/start.S |   4 +-
 arch/powerpc/cpu/mpc8xx/Kconfig  |   6 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c   |   5 +-
 arch/powerpc/cpu/mpc8xx/speed.c  |   4 +-
 arch/powerpc/dts/Makefile|   1 +
 arch/powerpc/dts/cmpc885.dts |  12 +-
 arch/powerpc/dts/cmpcpro.dts | 189 +
 arch/powerpc/dts/mcr3000.dts |  20 +-
 arch/powerpc/include/asm/arch-mpc83xx/gpio.h |   5 +
 arch/powerpc/include/asm/arch-mpc83xx/soc.h  |  16 +-
 arch/powerpc/include/asm/mpc8xxx_spi.h   |   1 +
 board/cssi/MAINTAINERS   |   2 +
 board/cssi/cmpc885/Makefile  |   2 +-
 board/cssi/cmpc885/cmpc885.c | 241 ++-
 board/cssi/cmpcpro/Kconfig   |  26 ++
 board/cssi/cmpcpro/Makefile  |   8 +
 board/cssi/cmpcpro/cmpcpro.c | 404 +++
 board/cssi/cmpcpro/cmpcpro.env   |   8 +
 board/cssi/cmpcpro/nand.c|  43 ++
 board/cssi/common/common.c   | 219 ++
 board/cssi/common/common.h   |  15 +
 board/cssi/mcr3000/mcr3000.c |  14 -
 configs/CMPC885_defconfig|   4 +-
 configs/CMPCPRO_defconfig| 209 ++
 configs/MCR3000_defconfig|   5 +-
 drivers/clk/mpc83xx_clk.c|   7 +
 drivers/gpio/Kconfig |  18 +
 drivers/gpio/Makefile|   1 +
 drivers/gpio/qe_gpio.c   | 170 
 drivers/spi/mpc8xxx_spi.c|  13 +
 drivers/watchdog/Kconfig |  26 +-
 drivers/watchdog/Makefile|   2 +-
 drivers/watchdog/mpc8xx_wdt.c|  75 
 drivers/watchdog/mpc8xxx_wdt.c   | 112 +
 include/configs/cmpc885.h|   6 +
 include/configs/cmpcpro.h|  99 +
 40 files changed, 1660 insertions(+), 344 deletions(-)
 create mode 100644 arch/powerpc/dts/cmpcpro.dts
 create mode 100644 board/cssi/cmpcpro/Kconfig
 create mode 100644 board/cssi/cmpcpro/Makefile
 create mode 100644 board/cssi/cmpcpro/cmpcpro.c
 create mode 100644 board/cssi/cmpcpro/cmpcpro.env
 create mode 100644 board/cssi/cmpcpro/nand.c
 create mode 100644 board/cssi/common/common.c
 create mode 100644 board/cssi/common/common.h
 create mode 100644 configs/CMPCPRO_defconfig
 create mode 100644 drivers/gpio/qe_gpio.c
 delete mode 100644 drivers/watchdog/mpc8xx_wdt.c
 create mode 100644 drivers/watchdog/mpc8xxx_wdt.c
 create mode 100644 include/configs/cmpcpro.h

-- 
2.39.2



[PATCH v1 01/14] powerpc: mpc8xx: Migrate to CONFIG_SYS_CLK_FREQ

2023-04-06 Thread Christophe Leroy
8xx has CONFIG_8xx_GCLK_FREQ which is similar to
CONFIG_SYS_CLK_FREQ, and doesn't set CONFIG_SYS_CLK_FREQ.

Due to that, get_board_sys_clk() returns 0.

Remove CONFIG_8xx_GCLK_FREQ and use CONFIG_SYS_CLK_FREQ instead.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/cpu/mpc8xx/Kconfig | 3 ---
 arch/powerpc/cpu/mpc8xx/speed.c | 4 ++--
 configs/CMPC885_defconfig   | 2 +-
 configs/MCR3000_defconfig   | 2 +-
 4 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8xx/Kconfig b/arch/powerpc/cpu/mpc8xx/Kconfig
index 628d3617bc..a705014512 100644
--- a/arch/powerpc/cpu/mpc8xx/Kconfig
+++ b/arch/powerpc/cpu/mpc8xx/Kconfig
@@ -30,9 +30,6 @@ config MPC885
 
 endchoice
 
-config 8xx_GCLK_FREQ
-   int "CPU GCLK Frequency"
-
 comment "Specific commands"
 
 config CMD_IMMAP
diff --git a/arch/powerpc/cpu/mpc8xx/speed.c b/arch/powerpc/cpu/mpc8xx/speed.c
index ad3d3f9101..1a882a3882 100644
--- a/arch/powerpc/cpu/mpc8xx/speed.c
+++ b/arch/powerpc/cpu/mpc8xx/speed.c
@@ -14,7 +14,7 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 /*
- * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ
+ * get_clocks() fills in gd->cpu_clk depending on CONFIG_SYS_CLK_FREQ
  */
 int get_clocks(void)
 {
@@ -28,7 +28,7 @@ int get_clocks(void)
 * (For example, the cogent CMA286-60 CPU module has no
 * separate oscillator for PITRTCLK)
 */
-   gd->cpu_clk = CONFIG_8xx_GCLK_FREQ;
+   gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
 
if ((sccr & SCCR_EBDF11) == 0) {
/* No Bus Divider active */
diff --git a/configs/CMPC885_defconfig b/configs/CMPC885_defconfig
index 7dff6ff270..484a81b8d3 100644
--- a/configs/CMPC885_defconfig
+++ b/configs/CMPC885_defconfig
@@ -4,11 +4,11 @@ CONFIG_ENV_SECT_SIZE=0x2000
 CONFIG_DM_GPIO=y
 CONFIG_DEFAULT_DEVICE_TREE="cmpc885"
 CONFIG_SYS_PROMPT="S3K> "
+CONFIG_SYS_CLK_FREQ=13200
 CONFIG_ENV_ADDR=0x40004000
 CONFIG_MPC8xx=y
 CONFIG_TARGET_CMPC885=y
 CONFIG_MPC885=y
-CONFIG_8xx_GCLK_FREQ=13200
 CONFIG_CMD_IMMAP=y
 CONFIG_SYS_SIUMCR=0x0062
 CONFIG_SYS_SYPCR=0xFF8F
diff --git a/configs/MCR3000_defconfig b/configs/MCR3000_defconfig
index f96e9f06e1..4b5ce407ea 100644
--- a/configs/MCR3000_defconfig
+++ b/configs/MCR3000_defconfig
@@ -4,11 +4,11 @@ CONFIG_ENV_SIZE=0x2000
 CONFIG_ENV_SECT_SIZE=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="mcr3000"
 CONFIG_SYS_PROMPT="S3K> "
+CONFIG_SYS_CLK_FREQ=13200
 CONFIG_SYS_LOAD_ADDR=0x20
 CONFIG_ENV_ADDR=0x4004000
 CONFIG_MPC8xx=y
 CONFIG_TARGET_MCR3000=y
-CONFIG_8xx_GCLK_FREQ=13200
 CONFIG_CMD_IMMAP=y
 CONFIG_SYS_SIUMCR=0x00600400
 CONFIG_SYS_SYPCR=0xFF8F
-- 
2.39.2



Re: [GIT PULL] please pull fsl-qoriq-2023-4-6 for 2023.07-rc1

2023-04-06 Thread Tom Rini
On Thu, Apr 06, 2023 at 02:11:23AM +, Peng Fan wrote:

> Hi Tom,
> 
> Please pull fsl-qoriq-2023-4-6

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v3 12/12] arm: mach-k3: Remove empty sys_proto.h include

2023-04-06 Thread Andrew Davis
This header file is now empty, remove it.

Signed-off-by: Andrew Davis 
---
 arch/arm/mach-k3/am642_init.c |  2 --
 arch/arm/mach-k3/am654_init.c |  1 -
 arch/arm/mach-k3/common.c |  1 -
 arch/arm/mach-k3/include/mach/sys_proto.h | 10 --
 arch/arm/mach-k3/j721e_init.c |  1 -
 arch/arm/mach-k3/j721s2_init.c|  1 -
 arch/arm/mach-k3/security.c   |  1 -
 arch/arm/mach-k3/sysfw-loader.c   |  1 -
 board/siemens/iot2050/board.c |  1 -
 board/ti/am62ax/evm.c |  1 -
 board/ti/am62x/evm.c  |  1 -
 board/ti/am64x/evm.c  |  1 -
 board/ti/am65x/evm.c  |  2 --
 board/ti/j721e/evm.c  |  2 --
 board/ti/j721s2/evm.c |  2 --
 drivers/phy/phy-ti-am654.c|  1 -
 drivers/ram/k3-am654-ddrss.c  |  1 -
 17 files changed, 30 deletions(-)
 delete mode 100644 arch/arm/mach-k3/include/mach/sys_proto.h

diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index ef84aad819c..5d53358cf26 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -13,9 +13,7 @@
 #include 
 #include 
 #include "sysfw-loader.h"
-#include 
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/am654_init.c b/arch/arm/mach-k3/am654_init.c
index 2336da4b454..0d3889cde2b 100644
--- a/arch/arm/mach-k3/am654_init.c
+++ b/arch/arm/mach-k3/am654_init.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include "sysfw-loader.h"
-#include 
 #include "common.h"
 #include 
 #include 
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 9f2f5a98771..e29e51b7042 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
deleted file mode 100644
index 5638c6f8c8a..000
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
- * Andreas Dannenberg 
- */
-
-#ifndef _SYS_PROTO_H_
-#define _SYS_PROTO_H_
-
-#endif
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 31d324e2179..9bba5f79545 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -14,7 +14,6 @@
 #include 
 #include "sysfw-loader.h"
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
index 175ac4028a0..001d9466c20 100644
--- a/arch/arm/mach-k3/j721s2_init.c
+++ b/arch/arm/mach-k3/j721s2_init.c
@@ -14,7 +14,6 @@
 #include 
 #include "sysfw-loader.h"
 #include "common.h"
-#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm/mach-k3/security.c b/arch/arm/mach-k3/security.c
index 092588f4b5e..6179f7373aa 100644
--- a/arch/arm/mach-k3/security.c
+++ b/arch/arm/mach-k3/security.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "common.h"
diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
index c4c5c371100..9be2d9eaea2 100644
--- a/arch/arm/mach-k3/sysfw-loader.c
+++ b/arch/arm/mach-k3/sysfw-loader.c
@@ -23,7 +23,6 @@
 #include 
 
 #include 
-#include 
 #include "common.h"
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/board/siemens/iot2050/board.c b/board/siemens/iot2050/board.c
index 1ba3e90c6fc..2653e107450 100644
--- a/board/siemens/iot2050/board.c
+++ b/board/siemens/iot2050/board.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/am62ax/evm.c b/board/ti/am62ax/evm.c
index beef3f2f3da..f2dd3b4192e 100644
--- a/board/ti/am62ax/evm.c
+++ b/board/ti/am62ax/evm.c
@@ -7,7 +7,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/am62x/evm.c b/board/ti/am62x/evm.c
index 20b2a701223..034fbed3aa4 100644
--- a/board/ti/am62x/evm.c
+++ b/board/ti/am62x/evm.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
diff --git a/board/ti/am64x/evm.c b/board/ti/am64x/evm.c
index c88139ac7ac..b63792e 100644
--- a/board/ti/am64x/evm.c
+++ b/board/ti/am64x/evm.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "../common/board_detect.h"
diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index 4053b8333cf..706b2198183 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -13,7 +13,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -21,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "../common/board_detect.h"
 
diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c
index 00

[PATCH v3 11/12] arm: mach-k3: Move J721s2 SPL init functions to mach-k3

2023-04-06 Thread Andrew Davis
This matches AM64 and J721e and removes the need to forward
declare k3_spl_init(), k3_mem_init(), and check_rom_loaded_sysfw()
in sys_proto.h.

Signed-off-by: Andrew Davis 
Reviewed-by: Christian Gmeiner 
---
 arch/arm/mach-k3/include/mach/sys_proto.h |  3 --
 arch/arm/mach-k3/j721s2_init.c| 64 +++
 board/ti/j721s2/evm.c | 63 --
 3 files changed, 64 insertions(+), 66 deletions(-)

diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h 
b/arch/arm/mach-k3/include/mach/sys_proto.h
index 4b4e2a5be39..5638c6f8c8a 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -7,7 +7,4 @@
 #ifndef _SYS_PROTO_H_
 #define _SYS_PROTO_H_
 
-void k3_spl_init(void);
-void k3_mem_init(void);
-bool check_rom_loaded_sysfw(void);
 #endif
diff --git a/arch/arm/mach-k3/j721s2_init.c b/arch/arm/mach-k3/j721s2_init.c
index 4785a747bf3..175ac4028a0 100644
--- a/arch/arm/mach-k3/j721s2_init.c
+++ b/arch/arm/mach-k3/j721s2_init.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -182,6 +183,69 @@ void k3_mem_init(void)
spl_enable_dcache();
 }
 
+/* Support for the various EVM / SK families */
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+void do_dt_magic(void)
+{
+   int ret, rescan, mmc_dev = -1;
+   static struct mmc *mmc;
+
+   do_board_detect();
+
+   /*
+* Board detection has been done.
+* Let us see if another dtb wouldn't be a better match
+* for our board
+*/
+   if (IS_ENABLED(CONFIG_CPU_V7R)) {
+   ret = fdtdec_resetup(&rescan);
+   if (!ret && rescan) {
+   dm_uninit();
+   dm_init_and_scan(true);
+   }
+   }
+
+   /*
+* Because of multi DTB configuration, the MMC device has
+* to be re-initialized after reconfiguring FDT inorder to
+* boot from MMC. Do this when boot mode is MMC and ROM has
+* not loaded SYSFW.
+*/
+   switch (spl_boot_device()) {
+   case BOOT_DEVICE_MMC1:
+   mmc_dev = 0;
+   break;
+   case BOOT_DEVICE_MMC2:
+   case BOOT_DEVICE_MMC2_2:
+   mmc_dev = 1;
+   break;
+   }
+
+   if (mmc_dev > 0 && !check_rom_loaded_sysfw()) {
+   ret = mmc_init_device(mmc_dev);
+   if (!ret) {
+   mmc = find_mmc_device(mmc_dev);
+   if (mmc) {
+   ret = mmc_init(mmc);
+   if (ret)
+   printf("mmc init failed with error: 
%d\n", ret);
+   }
+   }
+   }
+}
+#endif
+
+#ifdef CONFIG_SPL_BUILD
+void board_init_f(ulong dummy)
+{
+   k3_spl_init();
+#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
+   do_dt_magic();
+#endif
+   k3_mem_init();
+}
+#endif
+
 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
switch (boot_device) {
diff --git a/board/ti/j721s2/evm.c b/board/ti/j721s2/evm.c
index 9b130c141ac..d3f9a655899 100644
--- a/board/ti/j721s2/evm.c
+++ b/board/ti/j721s2/evm.c
@@ -192,66 +192,3 @@ int board_late_init(void)
 void spl_board_init(void)
 {
 }
-
-/* Support for the various EVM / SK families */
-#if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT)
-void do_dt_magic(void)
-{
-   int ret, rescan, mmc_dev = -1;
-   static struct mmc *mmc;
-
-   do_board_detect();
-
-   /*
-* Board detection has been done.
-* Let us see if another dtb wouldn't be a better match
-* for our board
-*/
-   if (IS_ENABLED(CONFIG_CPU_V7R)) {
-   ret = fdtdec_resetup(&rescan);
-   if (!ret && rescan) {
-   dm_uninit();
-   dm_init_and_scan(true);
-   }
-   }
-
-   /*
-* Because of multi DTB configuration, the MMC device has
-* to be re-initialized after reconfiguring FDT inorder to
-* boot from MMC. Do this when boot mode is MMC and ROM has
-* not loaded SYSFW.
-*/
-   switch (spl_boot_device()) {
-   case BOOT_DEVICE_MMC1:
-   mmc_dev = 0;
-   break;
-   case BOOT_DEVICE_MMC2:
-   case BOOT_DEVICE_MMC2_2:
-   mmc_dev = 1;
-   break;
-   }
-
-   if (mmc_dev > 0 && !check_rom_loaded_sysfw()) {
-   ret = mmc_init_device(mmc_dev);
-   if (!ret) {
-   mmc = find_mmc_device(mmc_dev);
-   if (mmc) {
-   ret = mmc_init(mmc);
-   if (ret)
-   printf("mmc init failed with error: 
%d\n", ret);
-   }
-   }
-   }
-}
-#endif
-
-#

  1   2   >