Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 1 | /* |
Marek Vasut | d97f6ee | 2019-08-06 18:58:38 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved. |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <common/debug.h> |
| 8 | #include <lib/mmio.h> |
| 9 | |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 10 | #include "dram_sub_func.h" |
Marek Vasut | d97f6ee | 2019-08-06 18:58:38 +0200 | [diff] [blame] | 11 | #include "rcar_def.h" |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 12 | |
| 13 | #if RCAR_SYSTEM_SUSPEND |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 14 | /* Local defines */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 15 | #define DRAM_BACKUP_GPIO_USE (0) |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 16 | #include "iic_dvfs.h" |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 17 | #if PMIC_ROHM_BD9571 |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 18 | #define PMIC_SLAVE_ADDR (0x30U) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 19 | #define PMIC_BKUP_MODE_CNT (0x20U) |
| 20 | #define PMIC_QLLM_CNT (0x27U) |
| 21 | #define BIT_BKUP_CTRL_OUT ((uint8_t)(1U << 4U)) |
| 22 | #define BIT_QLLM_DDR0_EN ((uint8_t)(1U << 0U)) |
| 23 | #define BIT_QLLM_DDR1_EN ((uint8_t)(1U << 1U)) |
| 24 | #endif |
| 25 | |
| 26 | #define GPIO_OUTDT1 (0xE6051008U) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 27 | #define GPIO_OUTDT3 (0xE6053008U) |
| 28 | #define GPIO_INDT3 (0xE605300CU) |
| 29 | #define GPIO_OUTDT6 (0xE6055408U) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 30 | |
| 31 | #if DRAM_BACKUP_GPIO_USE == 1 |
| 32 | #define GPIO_BKUP_REQB_SHIFT_SALVATOR (9U) /* GP1_9 (BKUP_REQB) */ |
| 33 | #define GPIO_BKUP_REQB_SHIFT_EBISU (14U) /* GP6_14(BKUP_REQB) */ |
| 34 | #define GPIO_BKUP_REQB_SHIFT_CONDOR (1U) /* GP3_1 (BKUP_REQB) */ |
| 35 | #endif |
| 36 | #define GPIO_BKUP_TRG_SHIFT_SALVATOR (8U) /* GP1_8 (BKUP_TRG) */ |
| 37 | #define GPIO_BKUP_TRG_SHIFT_EBISU (13U) /* GP6_13(BKUP_TRG) */ |
| 38 | #define GPIO_BKUP_TRG_SHIFT_CONDOR (0U) /* GP3_0 (BKUP_TRG) */ |
| 39 | |
| 40 | #define DRAM_BKUP_TRG_LOOP_CNT (1000U) |
| 41 | #endif |
| 42 | |
| 43 | void rcar_dram_get_boot_status(uint32_t * status) |
| 44 | { |
| 45 | #if RCAR_SYSTEM_SUSPEND |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 46 | |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 47 | uint32_t reg_data; |
| 48 | uint32_t product; |
| 49 | uint32_t shift; |
| 50 | uint32_t gpio; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 51 | |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 52 | product = mmio_read_32(PRR) & PRR_PRODUCT_MASK; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 53 | if (product == PRR_PRODUCT_V3H) { |
| 54 | shift = GPIO_BKUP_TRG_SHIFT_CONDOR; |
| 55 | gpio = GPIO_INDT3; |
| 56 | } else if (product == PRR_PRODUCT_E3) { |
| 57 | shift = GPIO_BKUP_TRG_SHIFT_EBISU; |
| 58 | gpio = GPIO_INDT6; |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 59 | } else { |
| 60 | shift = GPIO_BKUP_TRG_SHIFT_SALVATOR; |
| 61 | gpio = GPIO_INDT1; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 64 | reg_data = mmio_read_32(gpio); |
| 65 | if (0U != (reg_data & ((uint32_t)1U << shift))) { |
| 66 | *status = DRAM_BOOT_STATUS_WARM; |
| 67 | } else { |
| 68 | *status = DRAM_BOOT_STATUS_COLD; |
| 69 | } |
| 70 | #else /* RCAR_SYSTEM_SUSPEND */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 71 | *status = DRAM_BOOT_STATUS_COLD; |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 72 | #endif /* RCAR_SYSTEM_SUSPEND */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | int32_t rcar_dram_update_boot_status(uint32_t status) |
| 76 | { |
| 77 | int32_t ret = 0; |
| 78 | #if RCAR_SYSTEM_SUSPEND |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 79 | uint32_t reg_data; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 80 | #if PMIC_ROHM_BD9571 |
| 81 | #if DRAM_BACKUP_GPIO_USE == 0 |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 82 | uint8_t bkup_mode_cnt = 0U; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 83 | #else |
| 84 | uint32_t reqb, outd; |
| 85 | #endif |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 86 | uint8_t qllm_cnt = 0U; |
| 87 | int32_t i2c_dvfs_ret = -1; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 88 | #endif |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 89 | uint32_t loop_count; |
| 90 | uint32_t product; |
| 91 | uint32_t trg; |
| 92 | uint32_t gpio; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 93 | |
| 94 | product = mmio_read_32(PRR) & PRR_PRODUCT_MASK; |
| 95 | if (product == PRR_PRODUCT_V3H) { |
| 96 | #if DRAM_BACKUP_GPIO_USE == 1 |
| 97 | reqb = GPIO_BKUP_REQB_SHIFT_CONDOR; |
| 98 | outd = GPIO_OUTDT3; |
| 99 | #endif |
| 100 | trg = GPIO_BKUP_TRG_SHIFT_CONDOR; |
| 101 | gpio = GPIO_INDT3; |
| 102 | } else if (product == PRR_PRODUCT_E3) { |
| 103 | #if DRAM_BACKUP_GPIO_USE == 1 |
| 104 | reqb = GPIO_BKUP_REQB_SHIFT_EBISU; |
| 105 | outd = GPIO_OUTDT6; |
| 106 | #endif |
| 107 | trg = GPIO_BKUP_TRG_SHIFT_EBISU; |
| 108 | gpio = GPIO_INDT6; |
| 109 | } else { |
| 110 | #if DRAM_BACKUP_GPIO_USE == 1 |
| 111 | reqb = GPIO_BKUP_REQB_SHIFT_SALVATOR; |
| 112 | outd = GPIO_OUTDT1; |
| 113 | #endif |
| 114 | trg = GPIO_BKUP_TRG_SHIFT_SALVATOR; |
| 115 | gpio = GPIO_INDT1; |
| 116 | } |
| 117 | |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 118 | if (status == DRAM_BOOT_STATUS_WARM) { |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 119 | #if DRAM_BACKUP_GPIO_USE==1 |
| 120 | mmio_setbits_32(outd, 1U << reqb); |
| 121 | #else |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 122 | #if PMIC_ROHM_BD9571 |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 123 | /* Set BKUP_CRTL_OUT=High (BKUP mode cnt register) */ |
| 124 | i2c_dvfs_ret = rcar_iic_dvfs_receive(PMIC_SLAVE_ADDR, |
| 125 | PMIC_BKUP_MODE_CNT, &bkup_mode_cnt); |
| 126 | if (0 != i2c_dvfs_ret) { |
| 127 | ERROR("BKUP mode cnt READ ERROR.\n"); |
| 128 | ret = DRAM_UPDATE_STATUS_ERR; |
| 129 | } else { |
| 130 | bkup_mode_cnt &= (uint8_t)~BIT_BKUP_CTRL_OUT; |
| 131 | i2c_dvfs_ret = rcar_iic_dvfs_send(PMIC_SLAVE_ADDR, |
| 132 | PMIC_BKUP_MODE_CNT, bkup_mode_cnt); |
| 133 | if (0 != i2c_dvfs_ret) { |
| 134 | ERROR("BKUP mode cnt WRITE ERROR. " |
| 135 | "value = %d\n", bkup_mode_cnt); |
| 136 | ret = DRAM_UPDATE_STATUS_ERR; |
| 137 | } |
| 138 | } |
| 139 | #endif /* PMIC_ROHM_BD9571 */ |
| 140 | #endif /* DRAM_BACKUP_GPIO_USE==1 */ |
| 141 | /* Wait BKUP_TRG=Low */ |
| 142 | loop_count = DRAM_BKUP_TRG_LOOP_CNT; |
| 143 | while (0U < loop_count) { |
| 144 | reg_data = mmio_read_32(gpio); |
| 145 | if ((reg_data & |
| 146 | ((uint32_t)1U << trg)) == 0U) { |
| 147 | break; |
| 148 | } |
| 149 | loop_count--; |
| 150 | } |
| 151 | if (0U == loop_count) { |
| 152 | ERROR( "\nWarm booting...\n" \ |
| 153 | " The potential of BKUP_TRG did not switch " \ |
| 154 | "to Low.\n If you expect the operation of " \ |
| 155 | "cold boot,\n check the board configuration" \ |
| 156 | " (ex, Dip-SW) and/or the H/W failure.\n"); |
| 157 | ret = DRAM_UPDATE_STATUS_ERR; |
| 158 | } |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 159 | } |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 160 | #if PMIC_ROHM_BD9571 |
Marek Vasut | 6c245a5 | 2018-12-12 18:06:39 +0100 | [diff] [blame] | 161 | if(0 == ret) { |
| 162 | qllm_cnt = (BIT_QLLM_DDR0_EN | BIT_QLLM_DDR1_EN); |
| 163 | i2c_dvfs_ret = rcar_iic_dvfs_send(PMIC_SLAVE_ADDR, |
| 164 | PMIC_QLLM_CNT, qllm_cnt); |
| 165 | if (0 != i2c_dvfs_ret) { |
| 166 | ERROR("QLLM cnt WRITE ERROR. " |
| 167 | "value = %d\n", qllm_cnt); |
| 168 | ret = DRAM_UPDATE_STATUS_ERR; |
| 169 | } |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 170 | } |
| 171 | #endif |
| 172 | #endif |
| 173 | return ret; |
| 174 | } |