10299c90fSStefan Roese /* 20299c90fSStefan Roese * Copyright (C) 2015 Stefan Roese <sr@denx.de> 30299c90fSStefan Roese * 40299c90fSStefan Roese * SPDX-License-Identifier: GPL-2.0+ 50299c90fSStefan Roese */ 60299c90fSStefan Roese 70299c90fSStefan Roese #include <common.h> 80299c90fSStefan Roese #include <i2c.h> 90299c90fSStefan Roese #include <miiphy.h> 100299c90fSStefan Roese #include <netdev.h> 110299c90fSStefan Roese #include <asm/io.h> 120299c90fSStefan Roese #include <asm/arch/cpu.h> 130299c90fSStefan Roese #include <asm/arch/soc.h> 140299c90fSStefan Roese 150299c90fSStefan Roese #include "../drivers/ddr/marvell/a38x/ddr3_a38x_topology.h" 160299c90fSStefan Roese #include <../serdes/a38x/high_speed_env_spec.h> 170299c90fSStefan Roese 180299c90fSStefan Roese DECLARE_GLOBAL_DATA_PTR; 190299c90fSStefan Roese 200299c90fSStefan Roese #define ETH_PHY_CTRL_REG 0 210299c90fSStefan Roese #define ETH_PHY_CTRL_POWER_DOWN_BIT 11 220299c90fSStefan Roese #define ETH_PHY_CTRL_POWER_DOWN_MASK (1 << ETH_PHY_CTRL_POWER_DOWN_BIT) 230299c90fSStefan Roese 240299c90fSStefan Roese /* 250299c90fSStefan Roese * Those values and defines are taken from the Marvell U-Boot version 260299c90fSStefan Roese * "u-boot-2013.01-15t1-clearfog" 270299c90fSStefan Roese */ 280299c90fSStefan Roese #define BOARD_GPP_OUT_ENA_LOW 0xffffffff 290299c90fSStefan Roese #define BOARD_GPP_OUT_ENA_MID 0xffffffff 300299c90fSStefan Roese 310299c90fSStefan Roese #define BOARD_GPP_OUT_VAL_LOW 0x0 320299c90fSStefan Roese #define BOARD_GPP_OUT_VAL_MID 0x0 330299c90fSStefan Roese #define BOARD_GPP_POL_LOW 0x0 340299c90fSStefan Roese #define BOARD_GPP_POL_MID 0x0 350299c90fSStefan Roese 360299c90fSStefan Roese /* IO expander on Marvell GP board includes e.g. fan enabling */ 370299c90fSStefan Roese struct marvell_io_exp { 380299c90fSStefan Roese u8 chip; 390299c90fSStefan Roese u8 addr; 400299c90fSStefan Roese u8 val; 410299c90fSStefan Roese }; 420299c90fSStefan Roese 430299c90fSStefan Roese static struct marvell_io_exp io_exp[] = { 440299c90fSStefan Roese { 0x20, 2, 0x40 }, /* Deassert both mini pcie reset signals */ 450299c90fSStefan Roese { 0x20, 6, 0xf9 }, 460299c90fSStefan Roese { 0x20, 2, 0x46 }, /* rst signals and ena USB3 current limiter */ 470299c90fSStefan Roese { 0x20, 6, 0xb9 }, 480299c90fSStefan Roese { 0x20, 3, 0x00 }, /* Set SFP_TX_DIS to zero */ 490299c90fSStefan Roese { 0x20, 7, 0xbf }, /* Drive SFP_TX_DIS to zero */ 500299c90fSStefan Roese }; 510299c90fSStefan Roese 520299c90fSStefan Roese static struct serdes_map board_serdes_map[] = { 530299c90fSStefan Roese {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0}, 540299c90fSStefan Roese {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0}, 550299c90fSStefan Roese {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, 560299c90fSStefan Roese {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, 570299c90fSStefan Roese {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, 580299c90fSStefan Roese {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0}, 590299c90fSStefan Roese }; 600299c90fSStefan Roese 610299c90fSStefan Roese int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) 620299c90fSStefan Roese { 630299c90fSStefan Roese *serdes_map_array = board_serdes_map; 640299c90fSStefan Roese *count = ARRAY_SIZE(board_serdes_map); 650299c90fSStefan Roese return 0; 660299c90fSStefan Roese } 670299c90fSStefan Roese 680299c90fSStefan Roese /* 690299c90fSStefan Roese * Define the DDR layout / topology here in the board file. This will 700299c90fSStefan Roese * be used by the DDR3 init code in the SPL U-Boot version to configure 710299c90fSStefan Roese * the DDR3 controller. 720299c90fSStefan Roese */ 730299c90fSStefan Roese static struct hws_topology_map board_topology_map = { 740299c90fSStefan Roese 0x1, /* active interfaces */ 750299c90fSStefan Roese /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ 760299c90fSStefan Roese { { { {0x1, 0, 0, 0}, 770299c90fSStefan Roese {0x1, 0, 0, 0}, 780299c90fSStefan Roese {0x1, 0, 0, 0}, 790299c90fSStefan Roese {0x1, 0, 0, 0}, 800299c90fSStefan Roese {0x1, 0, 0, 0} }, 810299c90fSStefan Roese SPEED_BIN_DDR_1600K, /* speed_bin */ 820299c90fSStefan Roese BUS_WIDTH_16, /* memory_width */ 830299c90fSStefan Roese MEM_4G, /* mem_size */ 840299c90fSStefan Roese DDR_FREQ_800, /* frequency */ 850299c90fSStefan Roese 0, 0, /* cas_l cas_wl */ 86*90bcc3d3SMarek Behún HWS_TEMP_LOW, /* temperature */ 87*90bcc3d3SMarek Behún HWS_TIM_DEFAULT} }, /* timing */ 880299c90fSStefan Roese 5, /* Num Of Bus Per Interface*/ 890299c90fSStefan Roese BUS_MASK_32BIT /* Busses mask */ 900299c90fSStefan Roese }; 910299c90fSStefan Roese 920299c90fSStefan Roese struct hws_topology_map *ddr3_get_topology_map(void) 930299c90fSStefan Roese { 940299c90fSStefan Roese /* Return the board topology as defined in the board code */ 950299c90fSStefan Roese return &board_topology_map; 960299c90fSStefan Roese } 970299c90fSStefan Roese 980299c90fSStefan Roese int board_early_init_f(void) 990299c90fSStefan Roese { 1000299c90fSStefan Roese /* Configure MPP */ 1010299c90fSStefan Roese writel(0x11111111, MVEBU_MPP_BASE + 0x00); 1020299c90fSStefan Roese writel(0x11111111, MVEBU_MPP_BASE + 0x04); 1030299c90fSStefan Roese writel(0x10400011, MVEBU_MPP_BASE + 0x08); 1040299c90fSStefan Roese writel(0x22043333, MVEBU_MPP_BASE + 0x0c); 1050299c90fSStefan Roese writel(0x44400002, MVEBU_MPP_BASE + 0x10); 1060299c90fSStefan Roese writel(0x41144004, MVEBU_MPP_BASE + 0x14); 1070299c90fSStefan Roese writel(0x40333333, MVEBU_MPP_BASE + 0x18); 1080299c90fSStefan Roese writel(0x00004444, MVEBU_MPP_BASE + 0x1c); 1090299c90fSStefan Roese 1100299c90fSStefan Roese /* Set GPP Out value */ 1110299c90fSStefan Roese writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00); 1120299c90fSStefan Roese writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00); 1130299c90fSStefan Roese 1140299c90fSStefan Roese /* Set GPP Polarity */ 1150299c90fSStefan Roese writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c); 1160299c90fSStefan Roese writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c); 1170299c90fSStefan Roese 1180299c90fSStefan Roese /* Set GPP Out Enable */ 1190299c90fSStefan Roese writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04); 1200299c90fSStefan Roese writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04); 1210299c90fSStefan Roese 1220299c90fSStefan Roese return 0; 1230299c90fSStefan Roese } 1240299c90fSStefan Roese 1250299c90fSStefan Roese int board_init(void) 1260299c90fSStefan Roese { 1270299c90fSStefan Roese int i; 1280299c90fSStefan Roese 1290299c90fSStefan Roese /* Address of boot parameters */ 1300299c90fSStefan Roese gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; 1310299c90fSStefan Roese 1320299c90fSStefan Roese /* Toggle GPIO41 to reset onboard switch and phy */ 1330299c90fSStefan Roese clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9)); 1340299c90fSStefan Roese clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9)); 135fb9765d5SPatrick Wildt /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */ 136fb9765d5SPatrick Wildt clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19)); 137fb9765d5SPatrick Wildt clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19)); 1380299c90fSStefan Roese mdelay(1); 1390299c90fSStefan Roese setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9)); 140fb9765d5SPatrick Wildt setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19)); 1410299c90fSStefan Roese mdelay(10); 1420299c90fSStefan Roese 1430299c90fSStefan Roese /* Init I2C IO expanders */ 1440299c90fSStefan Roese for (i = 0; i < ARRAY_SIZE(io_exp); i++) 1450299c90fSStefan Roese i2c_write(io_exp[i].chip, io_exp[i].addr, 1, &io_exp[i].val, 1); 1460299c90fSStefan Roese 1470299c90fSStefan Roese return 0; 1480299c90fSStefan Roese } 1490299c90fSStefan Roese 1500299c90fSStefan Roese int checkboard(void) 1510299c90fSStefan Roese { 1520299c90fSStefan Roese puts("Board: SolidRun ClearFog\n"); 1530299c90fSStefan Roese 1540299c90fSStefan Roese return 0; 1550299c90fSStefan Roese } 1560299c90fSStefan Roese 1570299c90fSStefan Roese int board_eth_init(bd_t *bis) 1580299c90fSStefan Roese { 1590299c90fSStefan Roese cpu_eth_init(bis); /* Built in controller(s) come first */ 1600299c90fSStefan Roese return pci_eth_init(bis); 1610299c90fSStefan Roese } 162