xref: /rk3399_rockchip-uboot/board/Marvell/db-88f6820-gp/db-88f6820-gp.c (revision e14b1169c0c5a1b362b41451006b492bd16f2fff)
12bae75a4SStefan Roese /*
22bae75a4SStefan Roese  * Copyright (C) 2015 Stefan Roese <sr@denx.de>
32bae75a4SStefan Roese  *
42bae75a4SStefan Roese  * SPDX-License-Identifier:	GPL-2.0+
52bae75a4SStefan Roese  */
62bae75a4SStefan Roese 
72bae75a4SStefan Roese #include <common.h>
82bae75a4SStefan Roese #include <i2c.h>
92bae75a4SStefan Roese #include <miiphy.h>
10ce2cb1d3SStefan Roese #include <netdev.h>
112bae75a4SStefan Roese #include <asm/io.h>
122bae75a4SStefan Roese #include <asm/arch/cpu.h>
132bae75a4SStefan Roese #include <asm/arch/soc.h>
142bae75a4SStefan Roese 
159e30b31dSStefan Roese #include "../drivers/ddr/marvell/a38x/ddr3_a38x_topology.h"
16544acb07SKevin Smith #include <../serdes/a38x/high_speed_env_spec.h>
179e30b31dSStefan Roese 
182bae75a4SStefan Roese DECLARE_GLOBAL_DATA_PTR;
192bae75a4SStefan Roese 
202bae75a4SStefan Roese #define ETH_PHY_CTRL_REG		0
212bae75a4SStefan Roese #define ETH_PHY_CTRL_POWER_DOWN_BIT	11
222bae75a4SStefan Roese #define ETH_PHY_CTRL_POWER_DOWN_MASK	(1 << ETH_PHY_CTRL_POWER_DOWN_BIT)
232bae75a4SStefan Roese 
242bae75a4SStefan Roese /*
252bae75a4SStefan Roese  * Those values and defines are taken from the Marvell U-Boot version
262bae75a4SStefan Roese  * "u-boot-2013.01-2014_T3.0"
272bae75a4SStefan Roese  */
282bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_OUT_ENA_LOW					\
292bae75a4SStefan Roese 	(~(BIT(1)  | BIT(4)  | BIT(6)  | BIT(7)  | BIT(8)  | BIT(9)  |	\
302bae75a4SStefan Roese 	   BIT(10) | BIT(11) | BIT(19) | BIT(22) | BIT(23) | BIT(25) |	\
312bae75a4SStefan Roese 	   BIT(26) | BIT(27) | BIT(29) | BIT(30) | BIT(31)))
322bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_OUT_ENA_MID					\
332bae75a4SStefan Roese 	(~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(15) |	\
342bae75a4SStefan Roese 	   BIT(16) | BIT(17) | BIT(18)))
352bae75a4SStefan Roese 
362bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_OUT_VAL_LOW	0x0
372bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_OUT_VAL_MID	0x0
382bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_POL_LOW	0x0
392bae75a4SStefan Roese #define DB_GP_88F68XX_GPP_POL_MID	0x0
402bae75a4SStefan Roese 
412bae75a4SStefan Roese /* IO expander on Marvell GP board includes e.g. fan enabling */
422bae75a4SStefan Roese struct marvell_io_exp {
432bae75a4SStefan Roese 	u8 chip;
442bae75a4SStefan Roese 	u8 addr;
452bae75a4SStefan Roese 	u8 val;
462bae75a4SStefan Roese };
472bae75a4SStefan Roese 
482bae75a4SStefan Roese static struct marvell_io_exp io_exp[] = {
492bae75a4SStefan Roese 	{ 0x20, 6, 0x20 }, /* Configuration registers: Bit on --> Input bits */
502bae75a4SStefan Roese 	{ 0x20, 7, 0xC3 }, /* Configuration registers: Bit on --> Input bits */
512bae75a4SStefan Roese 	{ 0x20, 2, 0x1D }, /* Output Data, register#0 */
522bae75a4SStefan Roese 	{ 0x20, 3, 0x18 }, /* Output Data, register#1 */
532bae75a4SStefan Roese 	{ 0x21, 6, 0xC3 }, /* Configuration registers: Bit on --> Input bits  */
542bae75a4SStefan Roese 	{ 0x21, 7, 0x31 }, /* Configuration registers: Bit on --> Input bits  */
552bae75a4SStefan Roese 	{ 0x21, 2, 0x08 }, /* Output Data, register#0 */
562bae75a4SStefan Roese 	{ 0x21, 3, 0xC0 }  /* Output Data, register#1 */
572bae75a4SStefan Roese };
582bae75a4SStefan Roese 
59544acb07SKevin Smith static struct serdes_map board_serdes_map[] = {
60544acb07SKevin Smith 	{PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
61544acb07SKevin Smith 	{SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
62544acb07SKevin Smith 	{SATA1, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
63544acb07SKevin Smith 	{SATA3, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
64544acb07SKevin Smith 	{SATA2, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
65544acb07SKevin Smith 	{USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}
66544acb07SKevin Smith };
67544acb07SKevin Smith 
hws_board_topology_load(struct serdes_map ** serdes_map_array,u8 * count)68490753acSKevin Smith int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
69544acb07SKevin Smith {
70490753acSKevin Smith 	*serdes_map_array = board_serdes_map;
71490753acSKevin Smith 	*count = ARRAY_SIZE(board_serdes_map);
72544acb07SKevin Smith 	return 0;
73544acb07SKevin Smith }
74544acb07SKevin Smith 
759e30b31dSStefan Roese /*
769e30b31dSStefan Roese  * Define the DDR layout / topology here in the board file. This will
779e30b31dSStefan Roese  * be used by the DDR3 init code in the SPL U-Boot version to configure
789e30b31dSStefan Roese  * the DDR3 controller.
799e30b31dSStefan Roese  */
809e30b31dSStefan Roese static struct hws_topology_map board_topology_map = {
819e30b31dSStefan Roese 	0x1, /* active interfaces */
829e30b31dSStefan Roese 	/* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
839e30b31dSStefan Roese 	{ { { {0x1, 0, 0, 0},
849e30b31dSStefan Roese 	      {0x1, 0, 0, 0},
859e30b31dSStefan Roese 	      {0x1, 0, 0, 0},
869e30b31dSStefan Roese 	      {0x1, 0, 0, 0},
879e30b31dSStefan Roese 	      {0x1, 0, 0, 0} },
889e30b31dSStefan Roese 	    SPEED_BIN_DDR_1866L,	/* speed_bin */
899e30b31dSStefan Roese 	    BUS_WIDTH_8,		/* memory_width */
909e30b31dSStefan Roese 	    MEM_4G,			/* mem_size */
919e30b31dSStefan Roese 	    DDR_FREQ_800,		/* frequency */
929e30b31dSStefan Roese 	    0, 0,			/* cas_l cas_wl */
93*90bcc3d3SMarek Behún 	    HWS_TEMP_LOW,		/* temperature */
94*90bcc3d3SMarek Behún 	    HWS_TIM_DEFAULT} },		/* timing */
959e30b31dSStefan Roese 	5,				/* Num Of Bus Per Interface*/
969e30b31dSStefan Roese 	BUS_MASK_32BIT			/* Busses mask */
979e30b31dSStefan Roese };
989e30b31dSStefan Roese 
ddr3_get_topology_map(void)999e30b31dSStefan Roese struct hws_topology_map *ddr3_get_topology_map(void)
1009e30b31dSStefan Roese {
1019e30b31dSStefan Roese 	/* Return the board topology as defined in the board code */
1029e30b31dSStefan Roese 	return &board_topology_map;
1039e30b31dSStefan Roese }
1049e30b31dSStefan Roese 
board_early_init_f(void)1052bae75a4SStefan Roese int board_early_init_f(void)
1062bae75a4SStefan Roese {
1072bae75a4SStefan Roese 	/* Configure MPP */
1082bae75a4SStefan Roese 	writel(0x11111111, MVEBU_MPP_BASE + 0x00);
1092bae75a4SStefan Roese 	writel(0x11111111, MVEBU_MPP_BASE + 0x04);
1102bae75a4SStefan Roese 	writel(0x11244011, MVEBU_MPP_BASE + 0x08);
1112bae75a4SStefan Roese 	writel(0x22222111, MVEBU_MPP_BASE + 0x0c);
1122bae75a4SStefan Roese 	writel(0x22200002, MVEBU_MPP_BASE + 0x10);
1132bae75a4SStefan Roese 	writel(0x30042022, MVEBU_MPP_BASE + 0x14);
1142bae75a4SStefan Roese 	writel(0x55550555, MVEBU_MPP_BASE + 0x18);
1152bae75a4SStefan Roese 	writel(0x00005550, MVEBU_MPP_BASE + 0x1c);
1162bae75a4SStefan Roese 
1172bae75a4SStefan Roese 	/* Set GPP Out value */
1182bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
1192bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
1202bae75a4SStefan Roese 
1212bae75a4SStefan Roese 	/* Set GPP Polarity */
1222bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
1232bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
1242bae75a4SStefan Roese 
1252bae75a4SStefan Roese 	/* Set GPP Out Enable */
1262bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
1272bae75a4SStefan Roese 	writel(DB_GP_88F68XX_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
1282bae75a4SStefan Roese 
1292bae75a4SStefan Roese 	return 0;
1302bae75a4SStefan Roese }
1312bae75a4SStefan Roese 
board_init(void)1322bae75a4SStefan Roese int board_init(void)
1332bae75a4SStefan Roese {
1342bae75a4SStefan Roese 	int i;
1352bae75a4SStefan Roese 
1362bae75a4SStefan Roese 	/* adress of boot parameters */
1372bae75a4SStefan Roese 	gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
1382bae75a4SStefan Roese 
1392bae75a4SStefan Roese 	/* Init I2C IO expanders */
1402bae75a4SStefan Roese 	for (i = 0; i < ARRAY_SIZE(io_exp); i++)
1412bae75a4SStefan Roese 		i2c_write(io_exp[i].chip, io_exp[i].addr, 1, &io_exp[i].val, 1);
1422bae75a4SStefan Roese 
1432bae75a4SStefan Roese 	return 0;
1442bae75a4SStefan Roese }
1452bae75a4SStefan Roese 
checkboard(void)1462bae75a4SStefan Roese int checkboard(void)
1472bae75a4SStefan Roese {
1482bae75a4SStefan Roese 	puts("Board: Marvell DB-88F6820-GP\n");
1492bae75a4SStefan Roese 
1502bae75a4SStefan Roese 	return 0;
1512bae75a4SStefan Roese }
152ce2cb1d3SStefan Roese 
board_eth_init(bd_t * bis)153ce2cb1d3SStefan Roese int board_eth_init(bd_t *bis)
154ce2cb1d3SStefan Roese {
155ce2cb1d3SStefan Roese 	cpu_eth_init(bis); /* Built in controller(s) come first */
156ce2cb1d3SStefan Roese 	return pci_eth_init(bis);
157ce2cb1d3SStefan Roese }
158