From patchwork Wed Apr 19 11:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Torsten Duwe X-Patchwork-Id: 1770689 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1dp02W25z1ybF for ; Wed, 19 Apr 2023 21:28:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75CAC86235; Wed, 19 Apr 2023 13:28:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 448F285A83; Wed, 19 Apr 2023 13:28:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DE2F486268 for ; Wed, 19 Apr 2023 13:28:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=duwe@lst.de Received: by verein.lst.de (Postfix, from userid 2005) id 9638A68AFE; Wed, 19 Apr 2023 13:28:01 +0200 (CEST) Date: Wed, 19 Apr 2023 13:28:01 +0200 From: Torsten Duwe To: yanhong wang Cc: u-boot@lists.denx.de, Rick Chen , Leo , Lukasz Majewski , Sean Anderson , Lee Kuan Lim , Jianlong Huang , Emil Renner Berthing , Matthias Brugger Subject: [RFC] riscv: visionfive2: use OF_BOARD_SETUP Message-ID: <20230419112801.GA1907@lst.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean U-Boot already has a mechanism to fix up the DT before OS boot. This avoids the excessive duplication of data and work proposed by the explicit separation of 1.2a and 1.3b board revisions. It will also, to a good degree, improve the user experience, as pointed out by Matthias. The defconfig changes required (in diffconfig format) are -I2C n -NET_RANDOM_ETHADDR y +CMD_I2C y +CMD_MISC y +DM_I2C y +I2C_EEPROM y +MISC y +MISC_INIT_R y +OF_BOARD_SETUP y +SPL_DM_I2C n +SPL_MISC n +SYS_I2C_DW y +SYS_I2C_EEPROM_ADDR 0x0 along with the patch below. It has the neat side effect of providing the network with the proper MAC addresses ;) I take advantage of the fact that I²C-5 is also required to talk to the PMIC, so it must already be initialised by OpenSBI. All that's required is to declare the EEPROM and to pull in the drivers. This is only a proof of concept; let me know if you like it and I can add the other 12 DT patches to adjust_for_rev13b(), or maybe start with 1.3b as the default and go the other way, or something in between. The last hunk, to the i2c Makefile, is IMHO an independent fix, because the implication PCI => ACPI in designware_i2c_pci is invalid, and the VisionFive2 config proves it. Use this quick hack for now. Signed-off-by: Torsten Duwe diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi index ff9df56ec2..fd3a1d057a 100644 --- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi @@ -119,6 +119,12 @@ pinctrl-names = "default"; pinctrl-0 = <&i2c5_pins>; status = "okay"; + + eeprom@50 { + compatible = "atmel,24c04"; + reg = <0x50>; + pagesize = <0x10>; + }; }; &i2c6 { diff --git a/board/starfive/visionfive2/starfive_visionfive2.c b/board/starfive/visionfive2/starfive_visionfive2.c index 613fe793c4..d7f846a357 100644 --- a/board/starfive/visionfive2/starfive_visionfive2.c +++ b/board/starfive/visionfive2/starfive_visionfive2.c @@ -7,6 +7,10 @@ #include #include #include +#include +#include +#include +#include #include #define JH7110_L2_PREFETCHER_BASE_ADDR 0x2030000 @@ -38,3 +42,62 @@ int board_init(void) return 0; } + +#ifdef CONFIG_MISC_INIT_R +int misc_init_r(void) +{ + int ret = 0; + +#ifdef CONFIG_I2C_EEPROM + struct udevice *dev; + char mac_addr[6]; + unsigned char pcb_rev, BOM; + + ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); + if (ret) + goto out; + + if (eth_env_get_enetaddr("ethaddr", mac_addr) == 0) { + int i; + for (i=0; i<2; i++) { + ret = i2c_eeprom_read(dev, 0x78+6*i, mac_addr, 6); + if (!ret && is_valid_ethaddr(mac_addr)) + eth_env_set_enetaddr_by_index("eth", i, mac_addr); + } + } + + ret = i2c_eeprom_read(dev, 0x76, &pcb_rev, 1); + if (!ret) + env_set_hex("board_revision", pcb_rev); + + ret = i2c_eeprom_read(dev, 0x77, &BOM, 1); + + out: +#endif + return ret; +} +#endif + +#ifdef CONFIG_OF_BOARD_SETUP +static void adjust_for_rev13b(void * fdt) +{ + do_fixup_by_path(fdt, "/soc/ethernet@16040000", + "phy-mode", "rgmii-id", 9, 0); + /* + ... other fixups ... + + */ +} + +int ft_board_setup(void *fdt, struct bd_info *bdip) +{ + unsigned char pcb_rev = 0; + + pcb_rev = env_get_hex("board_revision", pcb_rev); + if (pcb_rev >= 0xB2) { + printf("Adjusting FDT for v1.3B board rev\n"); + adjust_for_rev13b(fdt); + } + return 0; +} +#endif diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index 99545df2e5..828856e40d 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -19,8 +19,10 @@ obj-$(CONFIG_SYS_I2C_CA) += i2c-cortina.o obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o ifdef CONFIG_PCI +ifdef CONFIG_ACPIGEN obj-$(CONFIG_SYS_I2C_DW) += designware_i2c_pci.o endif +endif obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o