blob: ab8eabbc6d8f9eff631700b1379baeea5c15f774 [file] [log] [blame]
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +02001/*
Marek Vasutd97f6ee2019-08-06 18:58:38 +02002 * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <common/debug.h>
8#include <lib/mmio.h>
9
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020010#include "dram_sub_func.h"
Marek Vasutd97f6ee2019-08-06 18:58:38 +020011#include "rcar_def.h"
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020012
13#if RCAR_SYSTEM_SUSPEND
Marek Vasut6c245a52018-12-12 18:06:39 +010014/* Local defines */
Marek Vasuta2e5d192019-08-07 18:05:05 +020015#define DRAM_BACKUP_GPIO_USE 0
Marek Vasut6c245a52018-12-12 18:06:39 +010016#include "iic_dvfs.h"
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020017#if PMIC_ROHM_BD9571
Marek Vasuta2e5d192019-08-07 18:05:05 +020018#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-Ortiz47503d22018-09-23 09:36:52 +020024#endif
25
Marek Vasuta2e5d192019-08-07 18:05:05 +020026#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-Ortiz47503d22018-09-23 09:36:52 +020032
Marek Vasuta2e5d192019-08-07 18:05:05 +020033#define DRAM_BKUP_TRG_LOOP_CNT 1000U
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020034#endif
35
Marek Vasuta2e5d192019-08-07 18:05:05 +020036void rcar_dram_get_boot_status(uint32_t *status)
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020037{
38#if RCAR_SYSTEM_SUSPEND
Marek Vasut6c245a52018-12-12 18:06:39 +010039 uint32_t reg_data;
40 uint32_t product;
41 uint32_t shift;
42 uint32_t gpio;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020043
Marek Vasut6c245a52018-12-12 18:06:39 +010044 product = mmio_read_32(PRR) & PRR_PRODUCT_MASK;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020045 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 Vasut6c245a52018-12-12 18:06:39 +010051 } else {
52 shift = GPIO_BKUP_TRG_SHIFT_SALVATOR;
53 gpio = GPIO_INDT1;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020054 }
55
Marek Vasut6c245a52018-12-12 18:06:39 +010056 reg_data = mmio_read_32(gpio);
Marek Vasuta2e5d192019-08-07 18:05:05 +020057 if (reg_data & BIT(shift))
Marek Vasut6c245a52018-12-12 18:06:39 +010058 *status = DRAM_BOOT_STATUS_WARM;
Marek Vasuta2e5d192019-08-07 18:05:05 +020059 else
Marek Vasut6c245a52018-12-12 18:06:39 +010060 *status = DRAM_BOOT_STATUS_COLD;
Marek Vasut6c245a52018-12-12 18:06:39 +010061#else /* RCAR_SYSTEM_SUSPEND */
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020062 *status = DRAM_BOOT_STATUS_COLD;
Marek Vasut6c245a52018-12-12 18:06:39 +010063#endif /* RCAR_SYSTEM_SUSPEND */
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020064}
65
66int32_t rcar_dram_update_boot_status(uint32_t status)
67{
68 int32_t ret = 0;
69#if RCAR_SYSTEM_SUSPEND
Marek Vasut6c245a52018-12-12 18:06:39 +010070 uint32_t reg_data;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020071#if PMIC_ROHM_BD9571
72#if DRAM_BACKUP_GPIO_USE == 0
Marek Vasut6c245a52018-12-12 18:06:39 +010073 uint8_t bkup_mode_cnt = 0U;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020074#else
75 uint32_t reqb, outd;
76#endif
Marek Vasut6c245a52018-12-12 18:06:39 +010077 uint8_t qllm_cnt = 0U;
78 int32_t i2c_dvfs_ret = -1;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020079#endif
Marek Vasut6c245a52018-12-12 18:06:39 +010080 uint32_t loop_count;
81 uint32_t product;
82 uint32_t trg;
83 uint32_t gpio;
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020084
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 Vasut6c245a52018-12-12 18:06:39 +0100109 if (status == DRAM_BOOT_STATUS_WARM) {
Marek Vasuta2e5d192019-08-07 18:05:05 +0200110#if DRAM_BACKUP_GPIO_USE == 1
111 mmio_setbits_32(outd, BIT(reqb));
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +0200112#else
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +0200113#if PMIC_ROHM_BD9571
Marek Vasut6c245a52018-12-12 18:06:39 +0100114 /* Set BKUP_CRTL_OUT=High (BKUP mode cnt register) */
115 i2c_dvfs_ret = rcar_iic_dvfs_receive(PMIC_SLAVE_ADDR,
Marek Vasuta2e5d192019-08-07 18:05:05 +0200116 PMIC_BKUP_MODE_CNT,
117 &bkup_mode_cnt);
118 if (i2c_dvfs_ret) {
Marek Vasut6c245a52018-12-12 18:06:39 +0100119 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 Vasuta2e5d192019-08-07 18:05:05 +0200124 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 Vasut6c245a52018-12-12 18:06:39 +0100129 ret = DRAM_UPDATE_STATUS_ERR;
130 }
131 }
132#endif /* PMIC_ROHM_BD9571 */
Marek Vasuta2e5d192019-08-07 18:05:05 +0200133#endif /* DRAM_BACKUP_GPIO_USE == 1 */
Marek Vasut6c245a52018-12-12 18:06:39 +0100134 /* Wait BKUP_TRG=Low */
135 loop_count = DRAM_BKUP_TRG_LOOP_CNT;
Marek Vasuta2e5d192019-08-07 18:05:05 +0200136 while (loop_count > 0) {
Marek Vasut6c245a52018-12-12 18:06:39 +0100137 reg_data = mmio_read_32(gpio);
Marek Vasuta2e5d192019-08-07 18:05:05 +0200138 if (!(reg_data & BIT(trg)))
Marek Vasut6c245a52018-12-12 18:06:39 +0100139 break;
Marek Vasut6c245a52018-12-12 18:06:39 +0100140 loop_count--;
141 }
Marek Vasuta2e5d192019-08-07 18:05:05 +0200142
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 Vasut6c245a52018-12-12 18:06:39 +0100148 ret = DRAM_UPDATE_STATUS_ERR;
149 }
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +0200150 }
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +0200151#if PMIC_ROHM_BD9571
Marek Vasuta2e5d192019-08-07 18:05:05 +0200152 if (!ret) {
153 qllm_cnt = BIT_QLLM_DDR0_EN | BIT_QLLM_DDR1_EN;
Marek Vasut6c245a52018-12-12 18:06:39 +0100154 i2c_dvfs_ret = rcar_iic_dvfs_send(PMIC_SLAVE_ADDR,
Marek Vasuta2e5d192019-08-07 18:05:05 +0200155 PMIC_QLLM_CNT,
156 qllm_cnt);
157 if (i2c_dvfs_ret) {
158 ERROR("QLLM cnt WRITE ERROR. value = %d\n", qllm_cnt);
Marek Vasut6c245a52018-12-12 18:06:39 +0100159 ret = DRAM_UPDATE_STATUS_ERR;
160 }
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +0200161 }
162#endif
163#endif
164 return ret;
165}