diff options
| author | Tom Rini <trini@konsulko.com> | 2021-06-10 13:27:14 -0400 |
|---|---|---|
| committer | Tom Rini <trini@konsulko.com> | 2021-06-10 13:27:14 -0400 |
| commit | cf066a20c3ec063d019a991cc32ba8ad95a39780 (patch) | |
| tree | e57916eaecbcd8c707407349ee3c18318a096ac5 /board | |
| parent | 0008d8086649d3bb3afd0c4697f5b73ccf6f293d (diff) | |
| parent | c64e2bd55883ede3dc29421f1f297d741ae5b137 (diff) | |
| download | u-boot-cf066a20c3ec063d019a991cc32ba8ad95a39780.tar.gz u-boot-cf066a20c3ec063d019a991cc32ba8ad95a39780.tar.xz u-boot-cf066a20c3ec063d019a991cc32ba8ad95a39780.zip | |
Merge https://source.denx.de/u-boot/custodians/u-boot-marvell
- mvebu: Turris MOX misc updates (cmds, rescue mode, LED's etc)
(Marek)
- mvebu: correct Armada 8K addresses (Heinrich)
Diffstat (limited to 'board')
| -rw-r--r-- | board/CZ.NIC/turris_mox/turris_mox.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 15cbf92550..44c272c7cb 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -10,11 +10,13 @@ #include <asm/global_data.h> #include <asm/io.h> #include <asm/gpio.h> +#include <button.h> #include <clk.h> #include <dm.h> #include <env.h> #include <fdt_support.h> #include <init.h> +#include <led.h> #include <linux/delay.h> #include <linux/libfdt.h> #include <linux/string.h> @@ -44,6 +46,8 @@ #define SFP_GPIO_PATH "/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0" #define PCIE_PATH "/soc/pcie@d0070000" #define SFP_PATH "/sfp" +#define LED_PATH "/leds/led" +#define BUTTON_PATH "/gpio-keys/reset" DECLARE_GLOBAL_DATA_PTR; @@ -373,6 +377,106 @@ int misc_init_r(void) return 0; } +static void mox_phy_modify(struct phy_device *phydev, int page, int reg, + u16 mask, u16 set) +{ + int val; + + val = phydev->drv->readext(phydev, MDIO_DEVAD_NONE, page, reg); + val &= ~mask; + val |= set; + phydev->drv->writeext(phydev, MDIO_DEVAD_NONE, page, reg, val); +} + +static void mox_phy_leds_start_blinking(void) +{ + struct phy_device *phydev; + struct mii_dev *bus; + + bus = miiphy_get_dev_by_name("neta@30000"); + if (!bus) { + printf("Cannot get MDIO bus device!\n"); + return; + } + + phydev = phy_find_by_mask(bus, BIT(1), PHY_INTERFACE_MODE_RGMII); + if (!phydev) { + printf("Cannot get ethernet PHY!\n"); + return; + } + + mox_phy_modify(phydev, 3, 0x12, 0x700, 0x400); + mox_phy_modify(phydev, 3, 0x10, 0xff, 0xbb); +} + +static bool read_reset_button(void) +{ + struct udevice *button, *led; + int i; + + if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) { + printf("Cannot find reset button!\n"); + return false; + } + + if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) { + printf("Cannot find status LED!\n"); + return false; + } + + led_set_state(led, LEDST_ON); + + for (i = 0; i < 21; ++i) { + if (button_get_state(button) != BUTTON_ON) + return false; + if (i < 20) + mdelay(50); + } + + led_set_state(led, LEDST_OFF); + + return true; +} + +static void handle_reset_button(void) +{ + if (read_reset_button()) { + const char * const vars[3] = { + "bootcmd", + "bootcmd_rescue", + "distro_bootcmd", + }; + + /* + * Set the above envs to their default values, in case the user + * managed to break them. + */ + env_set_default_vars(3, (char * const *)vars, 0); + + /* Ensure bootcmd_rescue is used by distroboot */ + env_set("boot_targets", "rescue"); + + /* start blinking PHY LEDs */ + mox_phy_leds_start_blinking(); + + printf("RESET button was pressed, overwriting boot_targets!\n"); + } else { + /* + * In case the user somehow managed to save environment with + * boot_targets=rescue, reset boot_targets to default value. + * This could happen in subsequent commands if bootcmd_rescue + * failed. + */ + if (!strcmp(env_get("boot_targets"), "rescue")) { + const char * const vars[1] = { + "boot_targets", + }; + + env_set_default_vars(1, (char * const *)vars, 0); + } + } +} + static void mox_print_info(void) { int ret, board_version, ram_size; @@ -543,6 +647,8 @@ int last_stage_init(void) printf("\n"); + handle_reset_button(); + return 0; } |
