From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CDF6D0C604 for ; Sat, 26 Oct 2024 16:17:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45D5F89058; Sat, 26 Oct 2024 18:16:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QPmbaIVq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8834A89021; Sat, 26 Oct 2024 17:52:43 +0200 (CEST) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9A6FA88EA8 for ; Sat, 26 Oct 2024 17:52:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=l.rubusch@gmail.com Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5c94c0bf354so428497a12.1 for ; Sat, 26 Oct 2024 08:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729957953; x=1730562753; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g24PlX+f7Q9JrGsECLdRHFJ1jIEI63ltoZxyzNejD1M=; b=QPmbaIVqTffecsoeM80nLA9uQDFklwqVQ24ZeAdvO2DK+WKly/b6KWjT8+2T3msgSU 8nAfH1OJ8IwafcYflSUjGiRbGpkoxBAAhhIZhm4qEhS3pzcJifPVR28YYtmAuJqf5fYt uzr0oC0+658A28S0D9MmD97Wwk6ljvWFoiQ/MYBL7+ScTvrjcky5bp9pmlw5bxjcnxvh DJA3UOmm+bgI4OgaME6ZwXfXf0H/rMcu+XKKDU9fSHWhj02m3hIBorS+AevoXNjgfZPY KflHzjpEbwZUSezV6mTcCdIq9o/xA6DTZaLxrqWtnspbrmwQ/YH3uOZYWfT4I9OY4wpQ 3DVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729957953; x=1730562753; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g24PlX+f7Q9JrGsECLdRHFJ1jIEI63ltoZxyzNejD1M=; b=cb+0Fr8MpI3e0ZI1rZIGTIwPeXf9xBDLAjZSFJLPO25PK3EFByF7RtXi3VbLBJldQQ 0tZ9kOhDEC1TdEq+Qu0z61Hmfxh+zgGffGcsWoFDuS8iE3V9tA1or6lRbYnNb/VHdxDa JHZbA3EfuRHhoCsH3kqWqwUJ3xUgBLVLnawiLIUTM26NpuG2gZ0vBS5l45J9BGTbyLjI OBIbE/LQTmJc9imZrYV6gjf8acY6FJWZEe9NpV64TWaNSN5dHvf9fSTO9zhFhb+ZZ4+I 0EZMzXbL/3h5aXYKioQectzyO5B7C+7nkvP+lAT/LPs09441oTrtyz0+PzSMjo9has9z Huzw== X-Gm-Message-State: AOJu0YzQASxVEOHYr4rlPfjUelLdoeP+KQkXnd6QLTkBgJDinbkQfvkV KhFrCaT80RFBugMEJqYdVZc6sQNhWmUZTdeSlbm1kGprA19RxGAqsK4a2A== X-Google-Smtp-Source: AGHT+IEknvHwCWr7dE//MXqPD3mjBni9Z0+5uXilNoHISYB8B7egRL51Uy911SG2ac9zsFoXUljE3A== X-Received: by 2002:a05:6402:51cb:b0:5c3:eb29:83ce with SMTP id 4fb4d7f45d1cf-5cbbfacb548mr930128a12.9.1729957952785; Sat, 26 Oct 2024 08:52:32 -0700 (PDT) Received: from 6c1d2e1f4cf4.v.cablecom.net (84-72-156-211.dclient.hispeed.ch. [84.72.156.211]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb63197casm1620179a12.63.2024.10.26.08.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 08:52:31 -0700 (PDT) From: Lothar Rubusch To: u-boot@lists.denx.de, trini@konsulko.com, marex@denx.de, simon.k.r.goldschmidt@gmail.com, tien.fong.chee@intel.com, sumit.garg@linaro.org Cc: sjg@chromium.org, xypron.glpk@gmx.de, michal.simek@amd.com, jit.loon.lim@intel.com, barnas@google.com, l.rubusch@gmail.com Subject: [PATCH v4 04/11] ARM: socfpga: add Enclustra storage switch Date: Sat, 26 Oct 2024 15:52:13 +0000 Message-Id: <20241026155220.26300-5-l.rubusch@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241026155220.26300-1-l.rubusch@gmail.com> References: <20241026155220.26300-1-l.rubusch@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 26 Oct 2024 18:16:43 +0200 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 Some of Enclustra's Intel SoMs need gpio muxing for setting up the boot media. This can be done by switching dip switches and also in software. The image in this case can be loaded from SD card, and flashed to the eMMC or QSPI. After, the dip switches can set the boot select accordingly. With altera_set_storage MMC|EMMC|QSPI from off the u-boot shell, the media is usually switched. Signed-off-by: Lothar Rubusch --- .../socfpga_arria10_enclustra_mercury_aa1.dts | 17 ++ board/enclustra/mercury_aa1/Makefile | 8 + .../mercury_aa1/aa1_set_storage_cmd.c | 190 ++++++++++++++++++ doc/board/enclustra/mercury-aa1.rst | 25 +++ 4 files changed, 240 insertions(+) create mode 100644 board/enclustra/mercury_aa1/Makefile create mode 100644 board/enclustra/mercury_aa1/aa1_set_storage_cmd.c diff --git a/arch/arm/dts/socfpga_arria10_enclustra_mercury_aa1.dts b/arch/arm/dts/socfpga_arria10_enclustra_mercury_aa1.dts index e8cc51a7b8..c038b2352e 100644 --- a/arch/arm/dts/socfpga_arria10_enclustra_mercury_aa1.dts +++ b/arch/arm/dts/socfpga_arria10_enclustra_mercury_aa1.dts @@ -5,6 +5,8 @@ /dts-v1/; +#include + /* The arria10 family */ #include "socfpga/socfpga_arria10_mercury_aa1.dtsi" @@ -17,6 +19,13 @@ i2c1 = &i2c0; spi0 = &qspi; }; + + altera_set_storage { + compatible = "enclustra,altera_set_storage"; + status = "okay"; + oe-gpios = <&portb 5 GPIO_ACTIVE_HIGH>; + sel-gpios = <&portc 6 GPIO_ACTIVE_HIGH>; + }; }; &qspi { @@ -35,6 +44,14 @@ }; }; +&gpio1 { + status = "okay"; +}; + +&gpio2 { + status = "okay"; +}; + /* Carrier board support */ #if IS_ENABLED(CONFIG_ENCLUSTRA_PE1) # include "socfpga/socfpga_enclustra_mercury_pe1.dtsi" diff --git a/board/enclustra/mercury_aa1/Makefile b/board/enclustra/mercury_aa1/Makefile new file mode 100644 index 0000000000..53c84d8156 --- /dev/null +++ b/board/enclustra/mercury_aa1/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2024 Enclustra GmbH + +ifeq ($(CONFIG_SPL_BUILD),) + +obj-y += aa1_set_storage_cmd.o + +endif diff --git a/board/enclustra/mercury_aa1/aa1_set_storage_cmd.c b/board/enclustra/mercury_aa1/aa1_set_storage_cmd.c new file mode 100644 index 0000000000..31c5ddb23b --- /dev/null +++ b/board/enclustra/mercury_aa1/aa1_set_storage_cmd.c @@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 Enclustra GmbH + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Pin muxing */ +#define ALTERA_NONE 0 +#define ALTERA_MMC 1 +#define ALTERA_QSPI 2 +#define ALTERA_EMMC 3 +#define MMC_CLK_DIV 0x9 +#define QSPI_CLK_DIV 0x384 +#define ALTERA_PINMUX_OFFS 0xffd07200 +#define ALTERA_CLKMGR_MAINPLL_CNTR6CLK_BASE 0xFFD04078 + +static int altera_current_storage = ALTERA_NONE; + +static const struct udevice_id altera_set_storage_match[] = { + { .compatible = "enclustra,altera_set_storage" }, + { } +}; + +U_BOOT_DRIVER(altera_set_storage) = { + .name = "altera_set_storage", + .id = UCLASS_MISC, + .of_match = altera_set_storage_match, +}; + +static void enclustra_mercury_aa1_write(const u32 *pinmux_arr, int len) +{ + u32 i, offset, value; + + for (i = 0; i < len; i += 2) { + offset = pinmux_arr[i]; + value = pinmux_arr[i + 1]; + writel(value, ALTERA_PINMUX_OFFS + offset); + } +} + +static void enclustra_mercury_aa1_set_mux_mmc(void) +{ + static const u32 pinmux_arr[] = {0x0c, 0x8, // IO4 connected to SDMMC + 0x10, 0x8, // IO5 + 0x14, 0x8, // IO6 + 0x18, 0x8, // IO7 + 0x1c, 0x8, // IO8 + 0x20, 0x8, // IO9 + 0x24, 0xf, // IO10 connected to GPIO + 0x28, 0xf, // IO11 + 0x2c, 0xf, // IO12 + 0x30, 0xf, // IO13 + 0x34, 0xf, // IO14 + 0x38, 0xf}; // IO15 + enclustra_mercury_aa1_write(pinmux_arr, ARRAY_SIZE(pinmux_arr)); +} + +static void enclustra_mercury_aa1_set_mux_emmc(void) +{ + static const u32 pinmux_arr[] = {0x0c, 0x8, // IO4 + 0x10, 0x8, // IO5 + 0x14, 0x8, // IO6 + 0x18, 0x8, // IO7 + 0x1c, 0x8, // IO8 + 0x20, 0x8, // IO9 + 0x24, 0xf, // IO10 + 0x28, 0xf, // IO11 + 0x2c, 0x8, // IO12 + 0x30, 0x8, // IO13 + 0x34, 0x8, // IO14 + 0x38, 0x8}; // IO15 + enclustra_mercury_aa1_write(pinmux_arr, ARRAY_SIZE(pinmux_arr)); +} + +static void enclustra_mercury_aa1_set_mux_qspi(void) +{ + static const u32 pinmux_arr[] = {0x0c, 0x4, // IO4 connected to QSPI + 0x10, 0x4, // IO5 + 0x14, 0x4, // IO6 + 0x18, 0x4, // IO7 + 0x1c, 0x4, // IO8 + 0x20, 0x4, // IO9 + 0x24, 0xf, // IO10 + 0x28, 0xf, // IO11 + 0x2c, 0xf, // IO12 + 0x30, 0xf, // IO13 + 0x34, 0xf, // IO14 + 0x38, 0xf}; // IO15 + enclustra_mercury_aa1_write(pinmux_arr, ARRAY_SIZE(pinmux_arr)); +} + +static int altera_set_storage(struct udevice *dev, int store) +{ + struct gpio_desc gpio_flash_sel; + struct gpio_desc gpio_flash_oe; + int ret; + + if (store == altera_current_storage) + return CMD_RET_FAILURE; + + /* oe: portb 5 */ + ret = gpio_request_by_name(dev, "oe-gpios", 0, + &gpio_flash_oe, GPIOD_IS_OUT); + + if (ret) { + printf("ERROR: GPIO oe not found\n"); + return log_msg_ret("gpio", ret); + } + + /* sel: portc 6 */ + ret = gpio_request_by_name(dev, "sel-gpios", 0, + &gpio_flash_sel, GPIOD_IS_OUT); + if (ret) { + printf("ERROR: GPIO sel not found\n"); + ret = CMD_RET_FAILURE; + goto err; + } + + switch (store) { + case ALTERA_MMC: + enclustra_mercury_aa1_set_mux_mmc(); + dm_gpio_set_value(&gpio_flash_sel, 0); + dm_gpio_set_value(&gpio_flash_oe, 0); + altera_current_storage = ALTERA_MMC; + writel(MMC_CLK_DIV, ALTERA_CLKMGR_MAINPLL_CNTR6CLK_BASE); + break; + case ALTERA_EMMC: + enclustra_mercury_aa1_set_mux_emmc(); + dm_gpio_set_value(&gpio_flash_sel, 1); + dm_gpio_set_value(&gpio_flash_oe, 1); + altera_current_storage = ALTERA_EMMC; + writel(MMC_CLK_DIV, ALTERA_CLKMGR_MAINPLL_CNTR6CLK_BASE); + break; + case ALTERA_QSPI: + enclustra_mercury_aa1_set_mux_qspi(); + dm_gpio_set_value(&gpio_flash_sel, 1); + dm_gpio_set_value(&gpio_flash_oe, 0); + altera_current_storage = ALTERA_QSPI; + writel(QSPI_CLK_DIV, ALTERA_CLKMGR_MAINPLL_CNTR6CLK_BASE); + break; + default: + altera_current_storage = ALTERA_NONE; + break; + } + + ret = CMD_RET_SUCCESS; + dm_gpio_free(dev, &gpio_flash_sel); +err: + dm_gpio_free(dev, &gpio_flash_oe); + + return ret; +} + +static int altera_set_storage_cmd(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(altera_set_storage), &dev); + if (ret) + return ret; + + if (argc != 2) + return CMD_RET_USAGE; + + if (!strcasecmp(argv[1], "mmc")) + return altera_set_storage(dev, ALTERA_MMC); + else if (!strcasecmp(argv[1], "qspi")) + return altera_set_storage(dev, ALTERA_QSPI); + else if (!strcasecmp(argv[1], "emmc")) + return altera_set_storage(dev, ALTERA_EMMC); + else + return CMD_RET_USAGE; + + return CMD_RET_FAILURE; +} + +U_BOOT_CMD(altera_set_storage, 2, 0, altera_set_storage_cmd, + "Set non volatile memory access", + " - Set access for the selected memory device"); diff --git a/doc/board/enclustra/mercury-aa1.rst b/doc/board/enclustra/mercury-aa1.rst index dec7cc3bdd..cba36aae2e 100644 --- a/doc/board/enclustra/mercury-aa1.rst +++ b/doc/board/enclustra/mercury-aa1.rst @@ -151,6 +151,31 @@ Alternative boot media are possible as officially documented by Enclustra. Note: eMMC and QSPI can be flashed from off the u-boot shell. Usually after flashing, the correct boot mode needs to be set by a BSEL switch. +In the u-boot shell use the following command to switch between the boot media. +This can be used to flash e.g. eMMC or QSPI with an image file stored on the SD +card. Approaches are described in detail in the official Enclustra +documentation according to their releases mentioned as links. + + .. code-block:: bash + + Hit any key to stop autoboot: 0 + => altera_set_storage + altera_set_storage - Set non volatile memory access + Usage: + altera_set_storage - Set access for the selected memory device + => altera_set_storage QSPI + => sf probe + SF: Detected s25fl512s with page size 256 Bytes, erase size 256 KiB, total 64 MiB + => altera_set_storage MMC + => mmc rescan + => mmc list + mmc@ff808000: 0 (SD) + => altera_set_storage EMMC + => mmc rescan + => mmc list + mmc@ff808000: 0 (eMMC) + => + Before turning on the setup, make sure to have the correct voltage configured at the carrier board, using the jumpers on the voltage pin header. Also make sure to have switched to the correct boot media using typically some dip -- 2.25.1