Tom Rini | 4549e78 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 4 | */ |
| 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 Delaunay | d46c22b | 2019-02-04 11:26:16 +0100 | [diff] [blame] | 11 | #include <power/stpmic1.h> |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 12 | |
Patrick Delaunay | 320d266 | 2018-05-17 14:50:46 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 14 | void 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 Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 40 | #ifdef CONFIG_PMIC_STPMIC1 |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 41 | int board_ddr_power_init(void) |
| 42 | { |
| 43 | struct udevice *dev; |
| 44 | int ret; |
| 45 | |
| 46 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 47 | DM_GET_DRIVER(pmic_stpmic1), &dev); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 48 | if (ret) |
| 49 | /* No PMIC on board */ |
| 50 | return 0; |
| 51 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 52 | /* VTT = Set LDO3 to sync mode */ |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 53 | ret = pmic_reg_read(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3)); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 54 | if (ret < 0) |
| 55 | return ret; |
| 56 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 57 | ret &= ~STPMIC1_LDO3_MODE; |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 58 | ret &= ~STPMIC1_LDO12356_VOUT_MASK; |
| 59 | ret |= STPMIC1_LDO_VOUT(STPMIC1_LDO3_DDR_SEL); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 60 | |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 61 | ret = pmic_reg_write(dev, STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3), |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 62 | ret); |
| 63 | if (ret < 0) |
| 64 | return ret; |
| 65 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 66 | /* VDD_DDR = Set BUCK2 to 1.35V */ |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 67 | ret = pmic_clrsetbits(dev, |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 68 | STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2), |
| 69 | STPMIC1_BUCK_VOUT_MASK, |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 70 | STPMIC1_BUCK2_1350000V); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 71 | if (ret < 0) |
| 72 | return ret; |
| 73 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 74 | /* Enable VDD_DDR = BUCK2 */ |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 75 | ret = pmic_clrsetbits(dev, |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 76 | STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK2), |
| 77 | STPMIC1_BUCK_ENA, STPMIC1_BUCK_ENA); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 78 | if (ret < 0) |
| 79 | return ret; |
| 80 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 81 | mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 82 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 83 | /* Enable VREF */ |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 84 | ret = pmic_clrsetbits(dev, STPMIC1_REFDDR_MAIN_CR, |
| 85 | STPMIC1_VREF_ENA, STPMIC1_VREF_ENA); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 86 | if (ret < 0) |
| 87 | return ret; |
| 88 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 89 | mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 90 | |
| 91 | /* Enable LDO3 */ |
| 92 | ret = pmic_clrsetbits(dev, |
Patrick Delaunay | db4ff0d | 2019-02-04 11:26:18 +0100 | [diff] [blame] | 93 | STPMIC1_LDOX_MAIN_CR(STPMIC1_LDO3), |
| 94 | STPMIC1_LDO_ENA, STPMIC1_LDO_ENA); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 95 | if (ret < 0) |
| 96 | return ret; |
| 97 | |
Patrick Delaunay | 42f01aa | 2019-02-04 11:26:17 +0100 | [diff] [blame] | 98 | mdelay(STPMIC1_DEFAULT_START_UP_DELAY_MS); |
Patrick Delaunay | f8598d9 | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | #endif |