blob: 5c1acca20d79dd3213357d99f99b02a09affe550 [file] [log] [blame]
Tom Rini4549e782018-05-06 18:27:01 -04001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Patrick Delaunayf8598d92018-03-12 10:46:18 +01002/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunayf8598d92018-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>
10#include <power/pmic.h>
Patrick Delaunayd46c22b2019-02-04 11:26:16 +010011#include <power/stpmic1.h>
Patrick Delaunayf8598d92018-03-12 10:46:18 +010012
Patrick Delaunay320d2662018-05-17 14:50:46 +020013#ifdef CONFIG_DEBUG_UART_BOARD_INIT
14void board_debug_uart_init(void)
15{
16#if (CONFIG_DEBUG_UART_BASE == STM32_UART4_BASE)
17
18#define RCC_MP_APB1ENSETR (STM32_RCC_BASE + 0x0A00)
19#define RCC_MP_AHB4ENSETR (STM32_RCC_BASE + 0x0A28)
20
21 /* UART4 clock enable */
22 setbits_le32(RCC_MP_APB1ENSETR, BIT(16));
23
24#define GPIOG_BASE 0x50008000
25 /* GPIOG clock enable */
26 writel(BIT(6), RCC_MP_AHB4ENSETR);
27 /* GPIO configuration for EVAL board
28 * => Uart4 TX = G11
29 */
30 writel(0xffbfffff, GPIOG_BASE + 0x00);
31 writel(0x00006000, GPIOG_BASE + 0x24);
32#else
33
34#error("CONFIG_DEBUG_UART_BASE: not supported value")
35
36#endif
37}
38#endif
39
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010040#ifdef CONFIG_PMIC_STPMIC1
Patrick Delaunayf8598d92018-03-12 10:46:18 +010041int board_ddr_power_init(void)
42{
43 struct udevice *dev;
44 int ret;
45
46 ret = uclass_get_device_by_driver(UCLASS_PMIC,
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010047 DM_GET_DRIVER(pmic_stpmic1), &dev);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010048 if (ret)
49 /* No PMIC on board */
50 return 0;
51
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010052 /* VTT = Set LDO3 to sync mode */
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010053 ret = pmic_reg_read(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3));
Patrick Delaunayf8598d92018-03-12 10:46:18 +010054 if (ret < 0)
55 return ret;
56
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010057 ret &= ~STPMIC1_LDO3_MODE;
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010058 ret &= ~STPMIC1_LDO12356_VOUT_MASK;
59 ret |= STPMIC1_LDO_VOUT(STPMIC1_LDO3_DDR_SEL);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010060
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010061 ret = pmic_reg_write(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
Patrick Delaunayf8598d92018-03-12 10:46:18 +010062 ret);
63 if (ret < 0)
64 return ret;
65
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010066 /* VDD_DDR = Set BUCK2 to 1.35V */
Patrick Delaunayf8598d92018-03-12 10:46:18 +010067 ret = pmic_clrsetbits(dev,
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010068 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
69 STPMIC1_BUCK_VOUT_MASK,
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010070 STPMIC1_BUCK2_1350000V);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010071 if (ret < 0)
72 return ret;
73
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010074 /* Enable VDD_DDR = BUCK2 */
Patrick Delaunayf8598d92018-03-12 10:46:18 +010075 ret = pmic_clrsetbits(dev,
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010076 STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2),
77 STPMIC1_BUCK_ENA, STPMIC1_BUCK_ENA);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010078 if (ret < 0)
79 return ret;
80
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010081 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010082
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010083 /* Enable VREF */
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010084 ret = pmic_clrsetbits(dev, STPMIC1_REFDDR_MAIN_CR,
85 STPMIC1_VREF_ENA, STPMIC1_VREF_ENA);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010086 if (ret < 0)
87 return ret;
88
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010089 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010090
91 /* Enable LDO3 */
92 ret = pmic_clrsetbits(dev,
Patrick Delaunaydb4ff0d2019-02-04 11:26:18 +010093 STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3),
94 STPMIC1_LDO_ENA, STPMIC1_LDO_ENA);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010095 if (ret < 0)
96 return ret;
97
Patrick Delaunay42f01aa2019-02-04 11:26:17 +010098 mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS);
Patrick Delaunayf8598d92018-03-12 10:46:18 +010099
100 return 0;
101}
102#endif