1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) Marvell International Ltd. and its affiliates
9 #include <asm/arch/cpu.h>
10 #include <asm/arch/soc.h>
13 #include "sys_env_lib.h"
15 #include "../../../drivers/ddr/marvell/a38x/ddr3_a38x.h"
17 #ifdef CONFIG_ARMADA_38X
18 enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
19 /* 6820 6810 6811 6828 */
20 /* PEX_UNIT_ID */ { 4, 3, 3, 4},
21 /* ETH_GIG_UNIT_ID */ { 3, 2, 3, 3},
22 /* USB3H_UNIT_ID */ { 2, 2, 2, 2},
23 /* USB3D_UNIT_ID */ { 1, 1, 1, 1},
24 /* SATA_UNIT_ID */ { 2, 2, 2, 4},
25 /* QSGMII_UNIT_ID */ { 1, 0, 0, 1},
26 /* XAUI_UNIT_ID */ { 0, 0, 0, 0},
27 /* RXAUI_UNIT_ID */ { 0, 0, 0, 0}
29 #else /* if (CONFIG_ARMADA_39X) */
30 enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
32 /* PEX_UNIT_ID */ { 4, 4},
33 /* ETH_GIG_UNIT_ID */ { 3, 4},
34 /* USB3H_UNIT_ID */ { 1, 2},
35 /* USB3D_UNIT_ID */ { 0, 1},
36 /* SATA_UNIT_ID */ { 0, 4},
37 /* QSGMII_UNIT_ID */ { 0, 1},
38 /* XAUI_UNIT_ID */ { 1, 1},
39 /* RXAUI_UNIT_ID */ { 1, 1}
45 u32 mv_board_id_get(void)
47 #if defined(CONFIG_TARGET_DB_88F6820_GP)
51 * Return 0 here for custom board as this should not be used
58 u32 mv_board_tclk_get(void)
62 value = (reg_read(DEVICE_SAMPLE_AT_RESET1_REG) >> 15) & 0x1;
74 u32 mv_board_id_index_get(u32 board_id)
77 * Marvell Boards use 0x10 as base for Board ID:
78 * mask MSB to receive index for board ID
80 return board_id & (MARVELL_BOARD_ID_MASK - 1);
84 * sys_env_suspend_wakeup_check
85 * DESCRIPTION: Reads GPIO input for suspend-wakeup indication.
88 * RETURNS: u32 indicating suspend wakeup status:
90 * 1 - supported: read magic word detect wakeup,
91 * 2 - detected wakeup from GPIO.
93 enum suspend_wakeup_status sys_env_suspend_wakeup_check(void)
95 u32 reg, board_id_index, gpio;
96 struct board_wakeup_gpio board_gpio[] = MV_BOARD_WAKEUP_GPIO_INFO;
98 board_id_index = mv_board_id_index_get(mv_board_id_get());
99 if (!(sizeof(board_gpio) / sizeof(struct board_wakeup_gpio) >
101 printf("\n_failed loading Suspend-Wakeup information (invalid board ID)\n");
102 return SUSPEND_WAKEUP_DISABLED;
106 * - Detect if Suspend-Wakeup is supported on current board
107 * - Fetch the GPIO number for wakeup status input indication
109 if (board_gpio[board_id_index].gpio_num == -1) {
110 /* Suspend to RAM is not supported */
111 return SUSPEND_WAKEUP_DISABLED;
112 } else if (board_gpio[board_id_index].gpio_num == -2) {
114 * Suspend to RAM is supported but GPIO indication is
115 * not implemented - Skip
117 return SUSPEND_WAKEUP_ENABLED;
119 gpio = board_gpio[board_id_index].gpio_num;
122 /* Initialize MPP for GPIO (set MPP = 0x0) */
123 reg = reg_read(MPP_CONTROL_REG(MPP_REG_NUM(gpio)));
124 /* reset MPP21 to 0x0, keep rest of MPP settings*/
125 reg &= ~MPP_MASK(gpio);
126 reg_write(MPP_CONTROL_REG(MPP_REG_NUM(gpio)), reg);
128 /* Initialize GPIO as input */
129 reg = reg_read(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)));
130 reg |= GPP_MASK(gpio);
131 reg_write(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)), reg);
134 * Check GPP for input status from PIC: 0 - regular init,
137 reg = reg_read(GPP_DATA_IN_REG(GPP_REG_NUM(gpio)));
139 /* if GPIO is ON: wakeup from S2RAM indication detected */
140 return (reg & GPP_MASK(gpio)) ? SUSPEND_WAKEUP_ENABLED_GPIO_DETECTED :
141 SUSPEND_WAKEUP_DISABLED;
145 * mv_ctrl_dev_id_index_get
147 * DESCRIPTION: return SOC device index
151 * return SOC device index
153 u32 sys_env_id_index_get(u32 ctrl_model)
155 switch (ctrl_model) {
157 return MV_6820_INDEX;
159 return MV_6810_INDEX;
161 return MV_6811_INDEX;
163 return MV_6828_INDEX;
165 return MV_6920_INDEX;
167 return MV_6928_INDEX;
169 return MV_6820_INDEX;
173 u32 sys_env_unit_max_num_get(enum unit_id unit)
177 if (unit >= MAX_UNITS_ID) {
178 printf("%s: Error: Wrong unit type (%u)\n", __func__, unit);
182 dev_id_index = sys_env_id_index_get(sys_env_model_get());
183 return sys_env_soc_unit_nums[unit][dev_id_index];
188 * DESCRIPTION: Returns 16bit describing the device model (ID) as defined
189 * in Vendor ID configuration register
191 u16 sys_env_model_get(void)
193 u32 default_ctrl_id, ctrl_id = reg_read(DEV_ID_REG);
194 ctrl_id = (ctrl_id & (DEV_ID_REG_DEVICE_ID_MASK)) >>
195 DEV_ID_REG_DEVICE_ID_OFFS;
206 /* Device ID Default for A38x: 6820 , for A39x: 6920 */
207 #ifdef CONFIG_ARMADA_38X
208 default_ctrl_id = MV_6820_DEV_ID;
210 default_ctrl_id = MV_6920_DEV_ID;
212 printf("%s: Error retrieving device ID (%x), using default ID = %x\n",
213 __func__, ctrl_id, default_ctrl_id);
214 return default_ctrl_id;
219 * sys_env_device_id_get
220 * DESCRIPTION: Returns enum (0..7) index of the device model (ID)
222 u32 sys_env_device_id_get(void)
224 char *device_id_str[7] = {
225 "6810", "6820", "6811", "6828", "NONE", "6920", "6928"
231 g_dev_id = reg_read(DEVICE_SAMPLE_AT_RESET1_REG);
232 g_dev_id = g_dev_id >> SAR_DEV_ID_OFFS & SAR_DEV_ID_MASK;
233 printf("Detected Device ID %s\n", device_id_str[g_dev_id]);