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 #ifdef CONFIG_ARMADA_38X
16 enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
17 /* 6820 6810 6811 6828 */
18 /* PEX_UNIT_ID */ { 4, 3, 3, 4},
19 /* ETH_GIG_UNIT_ID */ { 3, 2, 3, 3},
20 /* USB3H_UNIT_ID */ { 2, 2, 2, 2},
21 /* USB3D_UNIT_ID */ { 1, 1, 1, 1},
22 /* SATA_UNIT_ID */ { 2, 2, 2, 4},
23 /* QSGMII_UNIT_ID */ { 1, 0, 0, 1},
24 /* XAUI_UNIT_ID */ { 0, 0, 0, 0},
25 /* RXAUI_UNIT_ID */ { 0, 0, 0, 0}
27 #else /* if (CONFIG_ARMADA_39X) */
28 enum unit_id sys_env_soc_unit_nums[MAX_UNITS_ID][MAX_DEV_ID_NUM] = {
30 /* PEX_UNIT_ID */ { 4, 4},
31 /* ETH_GIG_UNIT_ID */ { 3, 4},
32 /* USB3H_UNIT_ID */ { 1, 2},
33 /* USB3D_UNIT_ID */ { 0, 1},
34 /* SATA_UNIT_ID */ { 0, 4},
35 /* QSGMII_UNIT_ID */ { 0, 1},
36 /* XAUI_UNIT_ID */ { 1, 1},
37 /* RXAUI_UNIT_ID */ { 1, 1}
43 u32 mv_board_id_get(void)
45 #if defined(CONFIG_TARGET_DB_88F6820_GP)
49 * Return 0 here for custom board as this should not be used
56 u32 mv_board_tclk_get(void)
60 value = (reg_read(DEVICE_SAMPLE_AT_RESET1_REG) >> 15) & 0x1;
72 u32 mv_board_id_index_get(u32 board_id)
75 * Marvell Boards use 0x10 as base for Board ID:
76 * mask MSB to receive index for board ID
78 return board_id & (MARVELL_BOARD_ID_MASK - 1);
82 * sys_env_suspend_wakeup_check
83 * DESCRIPTION: Reads GPIO input for suspend-wakeup indication.
86 * RETURNS: u32 indicating suspend wakeup status:
88 * 1 - supported: read magic word detect wakeup,
89 * 2 - detected wakeup from GPIO.
91 enum suspend_wakeup_status sys_env_suspend_wakeup_check(void)
93 u32 reg, board_id_index, gpio;
94 struct board_wakeup_gpio board_gpio[] = MV_BOARD_WAKEUP_GPIO_INFO;
96 board_id_index = mv_board_id_index_get(mv_board_id_get());
97 if (!(sizeof(board_gpio) / sizeof(struct board_wakeup_gpio) >
99 printf("\n_failed loading Suspend-Wakeup information (invalid board ID)\n");
100 return SUSPEND_WAKEUP_DISABLED;
104 * - Detect if Suspend-Wakeup is supported on current board
105 * - Fetch the GPIO number for wakeup status input indication
107 if (board_gpio[board_id_index].gpio_num == -1) {
108 /* Suspend to RAM is not supported */
109 return SUSPEND_WAKEUP_DISABLED;
110 } else if (board_gpio[board_id_index].gpio_num == -2) {
112 * Suspend to RAM is supported but GPIO indication is
113 * not implemented - Skip
115 return SUSPEND_WAKEUP_ENABLED;
117 gpio = board_gpio[board_id_index].gpio_num;
120 /* Initialize MPP for GPIO (set MPP = 0x0) */
121 reg = reg_read(MPP_CONTROL_REG(MPP_REG_NUM(gpio)));
122 /* reset MPP21 to 0x0, keep rest of MPP settings*/
123 reg &= ~MPP_MASK(gpio);
124 reg_write(MPP_CONTROL_REG(MPP_REG_NUM(gpio)), reg);
126 /* Initialize GPIO as input */
127 reg = reg_read(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)));
128 reg |= GPP_MASK(gpio);
129 reg_write(GPP_DATA_OUT_EN_REG(GPP_REG_NUM(gpio)), reg);
132 * Check GPP for input status from PIC: 0 - regular init,
135 reg = reg_read(GPP_DATA_IN_REG(GPP_REG_NUM(gpio)));
137 /* if GPIO is ON: wakeup from S2RAM indication detected */
138 return (reg & GPP_MASK(gpio)) ? SUSPEND_WAKEUP_ENABLED_GPIO_DETECTED :
139 SUSPEND_WAKEUP_DISABLED;
143 * mv_ctrl_dev_id_index_get
145 * DESCRIPTION: return SOC device index
149 * return SOC device index
151 u32 sys_env_id_index_get(u32 ctrl_model)
153 switch (ctrl_model) {
155 return MV_6820_INDEX;
157 return MV_6810_INDEX;
159 return MV_6811_INDEX;
161 return MV_6828_INDEX;
163 return MV_6920_INDEX;
165 return MV_6928_INDEX;
167 return MV_6820_INDEX;
171 u32 sys_env_unit_max_num_get(enum unit_id unit)
175 if (unit >= MAX_UNITS_ID) {
176 printf("%s: Error: Wrong unit type (%u)\n", __func__, unit);
180 dev_id_index = sys_env_id_index_get(sys_env_model_get());
181 return sys_env_soc_unit_nums[unit][dev_id_index];
186 * DESCRIPTION: Returns 16bit describing the device model (ID) as defined
187 * in Vendor ID configuration register
189 u16 sys_env_model_get(void)
191 u32 default_ctrl_id, ctrl_id = reg_read(DEV_ID_REG);
192 ctrl_id = (ctrl_id & (DEV_ID_REG_DEVICE_ID_MASK)) >>
193 DEV_ID_REG_DEVICE_ID_OFFS;
204 /* Device ID Default for A38x: 6820 , for A39x: 6920 */
205 #ifdef CONFIG_ARMADA_38X
206 default_ctrl_id = MV_6820_DEV_ID;
208 default_ctrl_id = MV_6920_DEV_ID;
210 printf("%s: Error retrieving device ID (%x), using default ID = %x\n",
211 __func__, ctrl_id, default_ctrl_id);
212 return default_ctrl_id;
217 * sys_env_device_id_get
218 * DESCRIPTION: Returns enum (0..7) index of the device model (ID)
220 u32 sys_env_device_id_get(void)
222 char *device_id_str[7] = {
223 "6810", "6820", "6811", "6828", "NONE", "6920", "6928"
229 g_dev_id = reg_read(DEVICE_SAMPLE_AT_RESET1_REG);
230 g_dev_id = g_dev_id >> SAR_DEV_ID_OFFS & SAR_DEV_ID_MASK;
231 printf("Detected Device ID %s\n", device_id_str[g_dev_id]);
237 * sys_env_device_rev_get - Get Marvell controller device revision number
240 * This function returns 8bit describing the device revision as defined
241 * Revision ID Register.
250 * 8bit desscribing Marvell controller revision number
252 u8 sys_env_device_rev_get(void)
256 value = reg_read(DEV_VERSION_ID_REG);
257 return (value & (REVISON_ID_MASK)) >> REVISON_ID_OFFS;