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