system_manager.c 2.38 KB
Newer Older
1
/*
2
 * Copyright (C) 2013 Altera Corporation <www.altera.com>
3 4 5 6 7 8 9
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <asm/arch/system_manager.h>
10
#include <asm/arch/fpga_manager.h>
11 12 13

DECLARE_GLOBAL_DATA_PTR;

14 15 16
static struct socfpga_system_manager *sysmgr_regs =
	(struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/*
 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
 */
static void populate_sysmgr_fpgaintf_module(void)
{
	uint32_t handoff_val = 0;

	/* ISWGRP_HANDOFF_FPGAINTF */
	writel(0, &sysmgr_regs->iswgrp_handoff[2]);

	/* Enable the signal for those HPS peripherals that use FPGA. */
	if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_NAND;
	if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_EMAC1;
	if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_SDMMC;
	if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_EMAC0;
	if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_SPIM0;
	if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
		handoff_val |= SYSMGR_FPGAINTF_SPIM1;

	/* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
	based on pinmux setting */
	setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val);

	handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]);
	if (fpgamgr_test_fpga_ready()) {
		/* Enable the required signals only */
		writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module);
	}
}

54 55 56 57 58
/*
 * Configure all the pin muxes
 */
void sysmgr_pinmux_init(void)
{
59
	uint32_t regs = (uint32_t)&sysmgr_regs->emacio[0];
60
	const u8 *sys_mgr_init_table;
61
	unsigned int len;
62
	int i;
63

64 65 66
	sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);

	for (i = 0; i < len; i++) {
67 68
		writel(sys_mgr_init_table[i], regs);
		regs += sizeof(regs);
69
	}
70 71

	populate_sysmgr_fpgaintf_module();
72
}
73 74 75 76

/*
 * This bit allows the bootrom to configure the IOs after a warm reset.
 */
77
void sysmgr_config_warmrstcfgio(int enable)
78
{
79 80 81 82 83 84
	if (enable)
		setbits_le32(&sysmgr_regs->romcodegrp_ctrl,
			     SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
	else
		clrbits_le32(&sysmgr_regs->romcodegrp_ctrl,
			     SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
85
}