blob: b0d165028ca5b3232cd157c9008816ac1275348d [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +01004 */
5
6#include <common.h>
7#include <dm.h>
8#include <asm/io.h>
9#include <asm/arch/ddr.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010011#include <power/pmic.h>
Patrick Delaunay91be5942019-02-04 11:26:16 +010012#include <power/stpmic1.h>
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010013
Patrick Delaunay82168e82018-05-17 14:50:46 +020014#ifdef CONFIG_DEBUG_UART_BOARD_INIT
15void board_debug_uart_init(void)
16{
17#if (CONFIG_DEBUG_UART_BASE == STM32_UART4_BASE)
18
19#define RCC_MP_APB1ENSETR (STM32_RCC_BASE + 0x0A00)
20#define RCC_MP_AHB4ENSETR (STM32_RCC_BASE + 0x0A28)
21
22 /* UART4 clock enable */
23 setbits_le32(RCC_MP_APB1ENSETR, BIT(16));
24
25#define GPIOG_BASE 0x50008000
26 /* GPIOG clock enable */
27 writel(BIT(6), RCC_MP_AHB4ENSETR);
28 /* GPIO configuration for EVAL board
29 * => Uart4 TX = G11
30 */
31 writel(0xffbfffff, GPIOG_BASE + 0x00);
32 writel(0x00006000, GPIOG_BASE + 0x24);
33#else
34
35#error("CONFIG_DEBUG_UART_BASE: not supported value")
36
37#endif
38}
39#endif
40
Patrick Delaunayd79218f2019-02-04 11:26:17 +010041#ifdef CONFIG_PMIC_STPMIC1
Patrick Delaunay4175f452019-04-10 14:09:26 +020042int board_ddr_power_init(enum ddr_type ddr_type)
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010043{
44 struct udevice *dev;
Patrick Delaunay4175f452019-04-10 14:09:26 +020045 bool buck3_at_1800000v = false;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010046 int ret;
Patrick Delaunay2ebc2112020-03-06 11:14:03 +010047 u32 buck2;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010048
49 ret = uclass_get_device_by_driver(UCLASS_PMIC,
Patrick Delaunayd79218f2019-02-04 11:26:17 +010050 DM_GET_DRIVER(pmic_stpmic1), &dev);
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010051 if (ret)
52 /* No PMIC on board */
53 return 0;
54
Patrick Delaunay4175f452019-04-10 14:09:26 +020055 switch (ddr_type) {
56 case STM32MP_DDR3:
57 /* VTT = Set LDO3 to sync mode */
58 ret = pmic_reg_read(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3));
59 if (ret < 0)
60 return ret;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010061
Patrick Delaunay4175f452019-04-10 14:09:26 +020062 ret &= ~STPMIC1_LDO3_MODE;
63 ret &= ~STPMIC1_LDO12356_VOUT_MASK;
64 ret |= STPMIC1_LDO_VOUT(STPMIC1_LDO3_DDR_SEL);
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010065
Patrick Delaunay4175f452019-04-10 14:09:26 +020066 ret = pmic_reg_write(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
67 ret);
68 if (ret < 0)
69 return ret;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010070
Patrick Delaunay4175f452019-04-10 14:09:26 +020071 /* VDD_DDR = Set BUCK2 to 1.35V */
72 ret = pmic_clrsetbits(dev,
73 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
74 STPMIC1_BUCK_VOUT_MASK,
75 STPMIC1_BUCK2_1350000V);
76 if (ret < 0)
77 return ret;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010078
Patrick Delaunay4175f452019-04-10 14:09:26 +020079 /* Enable VDD_DDR = BUCK2 */
80 ret = pmic_clrsetbits(dev,
81 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
82 STPMIC1_BUCK_ENA, STPMIC1_BUCK_ENA);
83 if (ret < 0)
84 return ret;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010085
Patrick Delaunay4175f452019-04-10 14:09:26 +020086 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010087
Patrick Delaunay4175f452019-04-10 14:09:26 +020088 /* Enable VREF */
89 ret = pmic_clrsetbits(dev, STPMIC1_REFDDR_MAIN_CR,
90 STPMIC1_VREF_ENA, STPMIC1_VREF_ENA);
91 if (ret < 0)
92 return ret;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010093
Patrick Delaunay4175f452019-04-10 14:09:26 +020094 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +010095
Patrick Delaunay4175f452019-04-10 14:09:26 +020096 /* Enable VTT = LDO3 */
97 ret = pmic_clrsetbits(dev,
98 STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
99 STPMIC1_LDO_ENA, STPMIC1_LDO_ENA);
100 if (ret < 0)
101 return ret;
102
103 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
104
105 break;
106
Patrick Delaunay2ebc2112020-03-06 11:14:03 +0100107 case STM32MP_LPDDR2_16:
108 case STM32MP_LPDDR2_32:
109 case STM32MP_LPDDR3_16:
110 case STM32MP_LPDDR3_32:
Patrick Delaunay4175f452019-04-10 14:09:26 +0200111 /*
112 * configure VDD_DDR1 = LDO3
113 * Set LDO3 to 1.8V
114 * + bypass mode if BUCK3 = 1.8V
115 * + normal mode if BUCK3 != 1.8V
116 */
117 ret = pmic_reg_read(dev,
118 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK3));
119 if (ret < 0)
120 return ret;
121
122 if ((ret & STPMIC1_BUCK3_1800000V) == STPMIC1_BUCK3_1800000V)
123 buck3_at_1800000v = true;
124
125 ret = pmic_reg_read(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3));
126 if (ret < 0)
127 return ret;
128
129 ret &= ~STPMIC1_LDO3_MODE;
130 ret &= ~STPMIC1_LDO12356_VOUT_MASK;
131 ret |= STPMIC1_LDO3_1800000;
132 if (buck3_at_1800000v)
133 ret |= STPMIC1_LDO3_MODE;
134
135 ret = pmic_reg_write(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
136 ret);
137 if (ret < 0)
138 return ret;
139
Patrick Delaunay2ebc2112020-03-06 11:14:03 +0100140 /* VDD_DDR2 : Set BUCK2 to 1.2V (16bits) or 1.25V (32 bits)*/
141 switch (ddr_type) {
142 case STM32MP_LPDDR2_32:
143 case STM32MP_LPDDR3_32:
144 buck2 = STPMIC1_BUCK2_1250000V;
145 break;
146 default:
147 case STM32MP_LPDDR2_16:
148 case STM32MP_LPDDR3_16:
149 buck2 = STPMIC1_BUCK2_1200000V;
150 break;
151 }
152
Patrick Delaunay4175f452019-04-10 14:09:26 +0200153 ret = pmic_clrsetbits(dev,
154 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
155 STPMIC1_BUCK_VOUT_MASK,
Patrick Delaunay2ebc2112020-03-06 11:14:03 +0100156 buck2);
Patrick Delaunay4175f452019-04-10 14:09:26 +0200157 if (ret < 0)
158 return ret;
159
160 /* Enable VDD_DDR1 = LDO3 */
161 ret = pmic_clrsetbits(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
162 STPMIC1_LDO_ENA, STPMIC1_LDO_ENA);
163 if (ret < 0)
164 return ret;
165
166 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
167
168 /* Enable VDD_DDR2 =BUCK2 */
169 ret = pmic_clrsetbits(dev,
170 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
171 STPMIC1_BUCK_ENA, STPMIC1_BUCK_ENA);
172 if (ret < 0)
173 return ret;
174
175 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
176
177 /* Enable VREF */
178 ret = pmic_clrsetbits(dev, STPMIC1_REFDDR_MAIN_CR,
179 STPMIC1_VREF_ENA, STPMIC1_VREF_ENA);
180 if (ret < 0)
181 return ret;
182
183 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
184
185 break;
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100186
Patrick Delaunay4175f452019-04-10 14:09:26 +0200187 default:
188 break;
189 };
Patrick Delaunay8eb3b1e2018-03-12 10:46:18 +0100190
191 return 0;
192}
193#endif