Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 1 | /* |
Patrice Chotard | 789ee0e | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
| 3 | * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics. |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
Patrice Chotard | 789ee0e | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 7 | |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 8 | #include <common.h> |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 11 | #include <stm32_rcc.h> |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 12 | |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 13 | #include <asm/io.h> |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 14 | #include <asm/arch/stm32.h> |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 15 | #include <asm/arch/stm32_pwr.h> |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 16 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 17 | #include <dt-bindings/mfd/stm32f7-rcc.h> |
| 18 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 19 | #define RCC_CR_HSION BIT(0) |
| 20 | #define RCC_CR_HSEON BIT(16) |
| 21 | #define RCC_CR_HSERDY BIT(17) |
| 22 | #define RCC_CR_HSEBYP BIT(18) |
| 23 | #define RCC_CR_CSSON BIT(19) |
| 24 | #define RCC_CR_PLLON BIT(24) |
| 25 | #define RCC_CR_PLLRDY BIT(25) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 26 | #define RCC_CR_PLLSAION BIT(28) |
| 27 | #define RCC_CR_PLLSAIRDY BIT(29) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 28 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 29 | #define RCC_PLLCFGR_PLLM_MASK GENMASK(5, 0) |
| 30 | #define RCC_PLLCFGR_PLLN_MASK GENMASK(14, 6) |
| 31 | #define RCC_PLLCFGR_PLLP_MASK GENMASK(17, 16) |
| 32 | #define RCC_PLLCFGR_PLLQ_MASK GENMASK(27, 24) |
| 33 | #define RCC_PLLCFGR_PLLSRC BIT(22) |
| 34 | #define RCC_PLLCFGR_PLLM_SHIFT 0 |
| 35 | #define RCC_PLLCFGR_PLLN_SHIFT 6 |
| 36 | #define RCC_PLLCFGR_PLLP_SHIFT 16 |
| 37 | #define RCC_PLLCFGR_PLLQ_SHIFT 24 |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 38 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 39 | #define RCC_CFGR_AHB_PSC_MASK GENMASK(7, 4) |
| 40 | #define RCC_CFGR_APB1_PSC_MASK GENMASK(12, 10) |
| 41 | #define RCC_CFGR_APB2_PSC_MASK GENMASK(15, 13) |
| 42 | #define RCC_CFGR_SW0 BIT(0) |
| 43 | #define RCC_CFGR_SW1 BIT(1) |
| 44 | #define RCC_CFGR_SW_MASK GENMASK(1, 0) |
| 45 | #define RCC_CFGR_SW_HSI 0 |
| 46 | #define RCC_CFGR_SW_HSE RCC_CFGR_SW0 |
| 47 | #define RCC_CFGR_SW_PLL RCC_CFGR_SW1 |
| 48 | #define RCC_CFGR_SWS0 BIT(2) |
| 49 | #define RCC_CFGR_SWS1 BIT(3) |
| 50 | #define RCC_CFGR_SWS_MASK GENMASK(3, 2) |
| 51 | #define RCC_CFGR_SWS_HSI 0 |
| 52 | #define RCC_CFGR_SWS_HSE RCC_CFGR_SWS0 |
| 53 | #define RCC_CFGR_SWS_PLL RCC_CFGR_SWS1 |
| 54 | #define RCC_CFGR_HPRE_SHIFT 4 |
| 55 | #define RCC_CFGR_PPRE1_SHIFT 10 |
| 56 | #define RCC_CFGR_PPRE2_SHIFT 13 |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 57 | |
Patrice Chotard | 9490aca | 2018-02-08 17:20:46 +0100 | [diff] [blame] | 58 | #define RCC_PLLSAICFGR_PLLSAIN_MASK GENMASK(14, 6) |
| 59 | #define RCC_PLLSAICFGR_PLLSAIP_MASK GENMASK(17, 16) |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 60 | #define RCC_PLLSAICFGR_PLLSAIQ_MASK GENMASK(27, 24) |
| 61 | #define RCC_PLLSAICFGR_PLLSAIR_MASK GENMASK(30, 28) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 62 | #define RCC_PLLSAICFGR_PLLSAIN_SHIFT 6 |
| 63 | #define RCC_PLLSAICFGR_PLLSAIP_SHIFT 16 |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 64 | #define RCC_PLLSAICFGR_PLLSAIQ_SHIFT 24 |
| 65 | #define RCC_PLLSAICFGR_PLLSAIR_SHIFT 28 |
Patrice Chotard | d5d3655 | 2018-01-19 18:02:40 +0100 | [diff] [blame] | 66 | #define RCC_PLLSAICFGR_PLLSAIP_4 BIT(16) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 67 | #define RCC_PLLSAICFGR_PLLSAIQ_4 BIT(26) |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 68 | #define RCC_PLLSAICFGR_PLLSAIR_3 BIT(29) | BIT(28) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 69 | |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 70 | #define RCC_DCKCFGRX_TIMPRE BIT(24) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 71 | #define RCC_DCKCFGRX_CK48MSEL BIT(27) |
| 72 | #define RCC_DCKCFGRX_SDMMC1SEL BIT(28) |
| 73 | #define RCC_DCKCFGR2_SDMMC2SEL BIT(29) |
| 74 | |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 75 | #define RCC_DCKCFGR_PLLSAIDIVR_SHIFT 16 |
| 76 | #define RCC_DCKCFGR_PLLSAIDIVR_MASK GENMASK(17, 16) |
| 77 | #define RCC_DCKCFGR_PLLSAIDIVR_2 0 |
| 78 | |
Patrice Chotard | 06fc648 | 2017-11-15 13:14:49 +0100 | [diff] [blame] | 79 | /* |
| 80 | * RCC AHB1ENR specific definitions |
| 81 | */ |
| 82 | #define RCC_AHB1ENR_ETHMAC_EN BIT(25) |
| 83 | #define RCC_AHB1ENR_ETHMAC_TX_EN BIT(26) |
| 84 | #define RCC_AHB1ENR_ETHMAC_RX_EN BIT(27) |
| 85 | |
| 86 | /* |
| 87 | * RCC APB1ENR specific definitions |
| 88 | */ |
| 89 | #define RCC_APB1ENR_TIM2EN BIT(0) |
| 90 | #define RCC_APB1ENR_PWREN BIT(28) |
| 91 | |
| 92 | /* |
| 93 | * RCC APB2ENR specific definitions |
| 94 | */ |
| 95 | #define RCC_APB2ENR_SYSCFGEN BIT(14) |
Patrice Chotard | e2d564e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 96 | #define RCC_APB2ENR_SAI1EN BIT(22) |
Patrice Chotard | 06fc648 | 2017-11-15 13:14:49 +0100 | [diff] [blame] | 97 | |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 98 | enum pllsai_div { |
| 99 | PLLSAIP, |
| 100 | PLLSAIQ, |
| 101 | PLLSAIR, |
| 102 | }; |
| 103 | |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 104 | static const struct stm32_clk_info stm32f4_clk_info = { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 105 | /* 180 MHz */ |
| 106 | .sys_pll_psc = { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 107 | .pll_n = 360, |
| 108 | .pll_p = 2, |
| 109 | .pll_q = 8, |
| 110 | .ahb_psc = AHB_PSC_1, |
| 111 | .apb1_psc = APB_PSC_4, |
| 112 | .apb2_psc = APB_PSC_2, |
| 113 | }, |
| 114 | .has_overdrive = false, |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 115 | .v2 = false, |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 118 | static const struct stm32_clk_info stm32f7_clk_info = { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 119 | /* 200 MHz */ |
| 120 | .sys_pll_psc = { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 121 | .pll_n = 400, |
| 122 | .pll_p = 2, |
| 123 | .pll_q = 8, |
| 124 | .ahb_psc = AHB_PSC_1, |
| 125 | .apb1_psc = APB_PSC_4, |
| 126 | .apb2_psc = APB_PSC_2, |
| 127 | }, |
| 128 | .has_overdrive = true, |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 129 | .v2 = true, |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 132 | struct stm32_clk { |
| 133 | struct stm32_rcc_regs *base; |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 134 | struct stm32_pwr_regs *pwr_regs; |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 135 | struct stm32_clk_info info; |
| 136 | unsigned long hse_rate; |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 137 | }; |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 138 | |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 139 | static const u8 pllsaidivr_table[] = { 2, 4, 8, 16 }; |
| 140 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 141 | static int configure_clocks(struct udevice *dev) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 142 | { |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 143 | struct stm32_clk *priv = dev_get_priv(dev); |
| 144 | struct stm32_rcc_regs *regs = priv->base; |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 145 | struct stm32_pwr_regs *pwr = priv->pwr_regs; |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 146 | struct pll_psc *sys_pll_psc = &priv->info.sys_pll_psc; |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 147 | |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 148 | /* Reset RCC configuration */ |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 149 | setbits_le32(®s->cr, RCC_CR_HSION); |
| 150 | writel(0, ®s->cfgr); /* Reset CFGR */ |
| 151 | clrbits_le32(®s->cr, (RCC_CR_HSEON | RCC_CR_CSSON |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 152 | | RCC_CR_PLLON | RCC_CR_PLLSAION)); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 153 | writel(0x24003010, ®s->pllcfgr); /* Reset value from RM */ |
| 154 | clrbits_le32(®s->cr, RCC_CR_HSEBYP); |
| 155 | writel(0, ®s->cir); /* Disable all interrupts */ |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 156 | |
| 157 | /* Configure for HSE+PLL operation */ |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 158 | setbits_le32(®s->cr, RCC_CR_HSEON); |
| 159 | while (!(readl(®s->cr) & RCC_CR_HSERDY)) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 160 | ; |
| 161 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 162 | setbits_le32(®s->cfgr, (( |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 163 | sys_pll_psc->ahb_psc << RCC_CFGR_HPRE_SHIFT) |
| 164 | | (sys_pll_psc->apb1_psc << RCC_CFGR_PPRE1_SHIFT) |
| 165 | | (sys_pll_psc->apb2_psc << RCC_CFGR_PPRE2_SHIFT))); |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 166 | |
| 167 | /* Configure the main PLL */ |
Patrice Chotard | b6653f6 | 2017-10-26 13:23:19 +0200 | [diff] [blame] | 168 | setbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLSRC); /* pll source HSE */ |
| 169 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLM_MASK, |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 170 | sys_pll_psc->pll_m << RCC_PLLCFGR_PLLM_SHIFT); |
Patrice Chotard | b6653f6 | 2017-10-26 13:23:19 +0200 | [diff] [blame] | 171 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLN_MASK, |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 172 | sys_pll_psc->pll_n << RCC_PLLCFGR_PLLN_SHIFT); |
Patrice Chotard | b6653f6 | 2017-10-26 13:23:19 +0200 | [diff] [blame] | 173 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLP_MASK, |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 174 | ((sys_pll_psc->pll_p >> 1) - 1) << RCC_PLLCFGR_PLLP_SHIFT); |
Patrice Chotard | b6653f6 | 2017-10-26 13:23:19 +0200 | [diff] [blame] | 175 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLQ_MASK, |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 176 | sys_pll_psc->pll_q << RCC_PLLCFGR_PLLQ_SHIFT); |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 177 | |
Patrice Chotard | cb15d28 | 2018-02-08 17:20:47 +0100 | [diff] [blame] | 178 | /* configure SDMMC clock */ |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 179 | if (priv->info.v2) { /*stm32f7 case */ |
Patrice Chotard | cb15d28 | 2018-02-08 17:20:47 +0100 | [diff] [blame] | 180 | /* select PLLQ as 48MHz clock source */ |
| 181 | clrbits_le32(®s->dckcfgr2, RCC_DCKCFGRX_CK48MSEL); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 182 | |
| 183 | /* select 48MHz as SDMMC1 clock source */ |
| 184 | clrbits_le32(®s->dckcfgr2, RCC_DCKCFGRX_SDMMC1SEL); |
| 185 | |
| 186 | /* select 48MHz as SDMMC2 clock source */ |
| 187 | clrbits_le32(®s->dckcfgr2, RCC_DCKCFGR2_SDMMC2SEL); |
| 188 | } else { /* stm32f4 case */ |
Patrice Chotard | cb15d28 | 2018-02-08 17:20:47 +0100 | [diff] [blame] | 189 | /* select PLLQ as 48MHz clock source */ |
| 190 | clrbits_le32(®s->dckcfgr, RCC_DCKCFGRX_CK48MSEL); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 191 | |
| 192 | /* select 48MHz as SDMMC1 clock source */ |
| 193 | clrbits_le32(®s->dckcfgr, RCC_DCKCFGRX_SDMMC1SEL); |
| 194 | } |
| 195 | |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 196 | #ifdef CONFIG_VIDEO_STM32 |
| 197 | /* |
| 198 | * Configure the SAI PLL to generate LTDC pixel clock |
| 199 | */ |
| 200 | clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIR_MASK, |
| 201 | RCC_PLLSAICFGR_PLLSAIR_3); |
| 202 | clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIN_MASK, |
| 203 | 195 << RCC_PLLSAICFGR_PLLSAIN_SHIFT); |
| 204 | |
| 205 | clrsetbits_le32(®s->dckcfgr, RCC_DCKCFGR_PLLSAIDIVR_MASK, |
| 206 | RCC_DCKCFGR_PLLSAIDIVR_2 << RCC_DCKCFGR_PLLSAIDIVR_SHIFT); |
| 207 | #endif |
Patrice Chotard | cb15d28 | 2018-02-08 17:20:47 +0100 | [diff] [blame] | 208 | /* Enable the main PLL */ |
| 209 | setbits_le32(®s->cr, RCC_CR_PLLON); |
| 210 | while (!(readl(®s->cr) & RCC_CR_PLLRDY)) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 211 | ; |
| 212 | |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 213 | #ifdef CONFIG_VIDEO_STM32 |
| 214 | /* Enable the SAI PLL */ |
| 215 | setbits_le32(®s->cr, RCC_CR_PLLSAION); |
| 216 | while (!(readl(®s->cr) & RCC_CR_PLLSAIRDY)) |
| 217 | ; |
| 218 | #endif |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 219 | setbits_le32(®s->apb1enr, RCC_APB1ENR_PWREN); |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 220 | |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 221 | if (priv->info.has_overdrive) { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 222 | /* |
| 223 | * Enable high performance mode |
| 224 | * System frequency up to 200 MHz |
| 225 | */ |
| 226 | setbits_le32(&pwr->cr1, PWR_CR1_ODEN); |
| 227 | /* Infinite wait! */ |
| 228 | while (!(readl(&pwr->csr1) & PWR_CSR1_ODRDY)) |
| 229 | ; |
| 230 | /* Enable the Over-drive switch */ |
| 231 | setbits_le32(&pwr->cr1, PWR_CR1_ODSWEN); |
| 232 | /* Infinite wait! */ |
| 233 | while (!(readl(&pwr->csr1) & PWR_CSR1_ODSWRDY)) |
| 234 | ; |
| 235 | } |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 236 | |
| 237 | stm32_flash_latency_cfg(5); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 238 | clrbits_le32(®s->cfgr, (RCC_CFGR_SW0 | RCC_CFGR_SW1)); |
| 239 | setbits_le32(®s->cfgr, RCC_CFGR_SW_PLL); |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 240 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 241 | while ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) != |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 242 | RCC_CFGR_SWS_PLL) |
| 243 | ; |
| 244 | |
Patrice Chotard | e2d564e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 245 | #ifdef CONFIG_ETH_DESIGNWARE |
| 246 | /* gate the SYSCFG clock, needed to set RMII ethernet interface */ |
| 247 | setbits_le32(®s->apb2enr, RCC_APB2ENR_SYSCFGEN); |
| 248 | #endif |
| 249 | |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 253 | static bool stm32_clk_get_ck48msel(struct stm32_clk *priv) |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 254 | { |
| 255 | struct stm32_rcc_regs *regs = priv->base; |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 256 | |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 257 | if (priv->info.v2) /*stm32f7 case */ |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 258 | return readl(®s->dckcfgr2) & RCC_DCKCFGRX_CK48MSEL; |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 259 | else |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 260 | |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 261 | return readl(®s->dckcfgr) & RCC_DCKCFGRX_CK48MSEL; |
| 262 | } |
| 263 | |
| 264 | static unsigned long stm32_clk_get_pllsai_vco_rate(struct stm32_clk *priv) |
| 265 | { |
| 266 | struct stm32_rcc_regs *regs = priv->base; |
| 267 | u16 pllm, pllsain; |
| 268 | |
| 269 | pllm = (readl(®s->pllcfgr) & RCC_PLLCFGR_PLLM_MASK); |
| 270 | pllsain = ((readl(®s->pllsaicfgr) & RCC_PLLSAICFGR_PLLSAIN_MASK) |
| 271 | >> RCC_PLLSAICFGR_PLLSAIN_SHIFT); |
| 272 | |
| 273 | return ((priv->hse_rate / pllm) * pllsain); |
| 274 | } |
| 275 | |
| 276 | static unsigned long stm32_clk_get_pllsai_rate(struct stm32_clk *priv, |
| 277 | enum pllsai_div output) |
| 278 | { |
| 279 | struct stm32_rcc_regs *regs = priv->base; |
| 280 | u16 pll_div_output; |
| 281 | |
| 282 | switch (output) { |
| 283 | case PLLSAIP: |
| 284 | pll_div_output = ((((readl(®s->pllsaicfgr) |
| 285 | & RCC_PLLSAICFGR_PLLSAIP_MASK) |
| 286 | >> RCC_PLLSAICFGR_PLLSAIP_SHIFT) + 1) << 1); |
| 287 | break; |
| 288 | case PLLSAIQ: |
| 289 | pll_div_output = (readl(®s->pllsaicfgr) |
| 290 | & RCC_PLLSAICFGR_PLLSAIQ_MASK) |
| 291 | >> RCC_PLLSAICFGR_PLLSAIQ_SHIFT; |
| 292 | break; |
| 293 | case PLLSAIR: |
| 294 | pll_div_output = (readl(®s->pllsaicfgr) |
| 295 | & RCC_PLLSAICFGR_PLLSAIR_MASK) |
| 296 | >> RCC_PLLSAICFGR_PLLSAIR_SHIFT; |
| 297 | break; |
| 298 | default: |
| 299 | pr_err("incorrect PLLSAI output %d\n", output); |
| 300 | return -EINVAL; |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 301 | } |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 302 | |
| 303 | return (stm32_clk_get_pllsai_vco_rate(priv) / pll_div_output); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 306 | static bool stm32_get_timpre(struct stm32_clk *priv) |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 307 | { |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 308 | struct stm32_rcc_regs *regs = priv->base; |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 309 | u32 val; |
| 310 | |
| 311 | if (priv->info.v2) /*stm32f7 case */ |
| 312 | val = readl(®s->dckcfgr2); |
| 313 | else |
| 314 | val = readl(®s->dckcfgr); |
| 315 | /* get timer prescaler */ |
| 316 | return !!(val & RCC_DCKCFGRX_TIMPRE); |
| 317 | } |
| 318 | |
| 319 | static u32 stm32_get_hclk_rate(struct stm32_rcc_regs *regs, u32 sysclk) |
| 320 | { |
| 321 | u8 shift; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 322 | /* Prescaler table lookups for clock computation */ |
| 323 | u8 ahb_psc_table[16] = { |
| 324 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9 |
| 325 | }; |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 326 | |
| 327 | shift = ahb_psc_table[( |
| 328 | (readl(®s->cfgr) & RCC_CFGR_AHB_PSC_MASK) |
| 329 | >> RCC_CFGR_HPRE_SHIFT)]; |
| 330 | |
| 331 | return sysclk >> shift; |
| 332 | }; |
| 333 | |
| 334 | static u8 stm32_get_apb_shift(struct stm32_rcc_regs *regs, enum apb apb) |
| 335 | { |
| 336 | /* Prescaler table lookups for clock computation */ |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 337 | u8 apb_psc_table[8] = { |
| 338 | 0, 0, 0, 0, 1, 2, 3, 4 |
| 339 | }; |
| 340 | |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 341 | if (apb == APB1) |
| 342 | return apb_psc_table[( |
| 343 | (readl(®s->cfgr) & RCC_CFGR_APB1_PSC_MASK) |
| 344 | >> RCC_CFGR_PPRE1_SHIFT)]; |
| 345 | else /* APB2 */ |
| 346 | return apb_psc_table[( |
| 347 | (readl(®s->cfgr) & RCC_CFGR_APB2_PSC_MASK) |
| 348 | >> RCC_CFGR_PPRE2_SHIFT)]; |
| 349 | }; |
| 350 | |
| 351 | static u32 stm32_get_timer_rate(struct stm32_clk *priv, u32 sysclk, |
| 352 | enum apb apb) |
| 353 | { |
| 354 | struct stm32_rcc_regs *regs = priv->base; |
| 355 | u8 shift = stm32_get_apb_shift(regs, apb); |
| 356 | |
| 357 | if (stm32_get_timpre(priv)) |
| 358 | /* |
| 359 | * if APB prescaler is configured to a |
| 360 | * division factor of 1, 2 or 4 |
| 361 | */ |
| 362 | switch (shift) { |
| 363 | case 0: |
| 364 | case 1: |
| 365 | case 2: |
| 366 | return stm32_get_hclk_rate(regs, sysclk); |
| 367 | default: |
| 368 | return (sysclk >> shift) * 4; |
| 369 | } |
| 370 | else |
| 371 | /* |
| 372 | * if APB prescaler is configured to a |
| 373 | * division factor of 1 |
| 374 | */ |
| 375 | if (shift == 0) |
| 376 | return sysclk; |
| 377 | else |
| 378 | return (sysclk >> shift) * 2; |
| 379 | }; |
| 380 | |
| 381 | static ulong stm32_clk_get_rate(struct clk *clk) |
| 382 | { |
| 383 | struct stm32_clk *priv = dev_get_priv(clk->dev); |
| 384 | struct stm32_rcc_regs *regs = priv->base; |
| 385 | u32 sysclk = 0; |
Patrice Chotard | 81d7765 | 2018-02-08 17:20:45 +0100 | [diff] [blame] | 386 | u32 vco; |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 387 | u32 sdmmcxsel_bit; |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 388 | u32 saidivr; |
| 389 | u32 pllsai_rate; |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 390 | u16 pllm, plln, pllp, pllq; |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 391 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 392 | if ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) == |
| 393 | RCC_CFGR_SWS_PLL) { |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 394 | pllm = (readl(®s->pllcfgr) & RCC_PLLCFGR_PLLM_MASK); |
| 395 | plln = ((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLN_MASK) |
| 396 | >> RCC_PLLCFGR_PLLN_SHIFT); |
| 397 | pllp = ((((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLP_MASK) |
| 398 | >> RCC_PLLCFGR_PLLP_SHIFT) + 1) << 1); |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 399 | pllq = ((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLQ_MASK) |
| 400 | >> RCC_PLLCFGR_PLLQ_SHIFT); |
Patrice Chotard | 81d7765 | 2018-02-08 17:20:45 +0100 | [diff] [blame] | 401 | vco = (priv->hse_rate / pllm) * plln; |
| 402 | sysclk = vco / pllp; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 403 | } else { |
| 404 | return -EINVAL; |
| 405 | } |
| 406 | |
| 407 | switch (clk->id) { |
| 408 | /* |
| 409 | * AHB CLOCK: 3 x 32 bits consecutive registers are used : |
| 410 | * AHB1, AHB2 and AHB3 |
| 411 | */ |
| 412 | case STM32F7_AHB1_CLOCK(GPIOA) ... STM32F7_AHB3_CLOCK(QSPI): |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 413 | return stm32_get_hclk_rate(regs, sysclk); |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 414 | /* APB1 CLOCK */ |
| 415 | case STM32F7_APB1_CLOCK(TIM2) ... STM32F7_APB1_CLOCK(UART8): |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 416 | /* For timer clock, an additionnal prescaler is used*/ |
| 417 | switch (clk->id) { |
| 418 | case STM32F7_APB1_CLOCK(TIM2): |
| 419 | case STM32F7_APB1_CLOCK(TIM3): |
| 420 | case STM32F7_APB1_CLOCK(TIM4): |
| 421 | case STM32F7_APB1_CLOCK(TIM5): |
| 422 | case STM32F7_APB1_CLOCK(TIM6): |
| 423 | case STM32F7_APB1_CLOCK(TIM7): |
| 424 | case STM32F7_APB1_CLOCK(TIM12): |
| 425 | case STM32F7_APB1_CLOCK(TIM13): |
| 426 | case STM32F7_APB1_CLOCK(TIM14): |
| 427 | return stm32_get_timer_rate(priv, sysclk, APB1); |
| 428 | } |
| 429 | return (sysclk >> stm32_get_apb_shift(regs, APB1)); |
| 430 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 431 | /* APB2 CLOCK */ |
| 432 | case STM32F7_APB2_CLOCK(TIM1) ... STM32F7_APB2_CLOCK(LTDC): |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 433 | switch (clk->id) { |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 434 | /* |
| 435 | * particular case for SDMMC1 and SDMMC2 : |
| 436 | * 48Mhz source clock can be from main PLL or from |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 437 | * PLLSAIP |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 438 | */ |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 439 | case STM32F7_APB2_CLOCK(SDMMC1): |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 440 | case STM32F7_APB2_CLOCK(SDMMC2): |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 441 | if (clk->id == STM32F7_APB2_CLOCK(SDMMC1)) |
| 442 | sdmmcxsel_bit = RCC_DCKCFGRX_SDMMC1SEL; |
| 443 | else |
| 444 | sdmmcxsel_bit = RCC_DCKCFGR2_SDMMC2SEL; |
| 445 | |
| 446 | if (readl(®s->dckcfgr2) & sdmmcxsel_bit) |
| 447 | /* System clock is selected as SDMMC1 clock */ |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 448 | return sysclk; |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 449 | /* |
| 450 | * 48 MHz can be generated by either PLLSAIP |
| 451 | * or by PLLQ depending of CK48MSEL bit of RCC_DCKCFGR |
| 452 | */ |
| 453 | if (stm32_clk_get_ck48msel(priv)) |
| 454 | return stm32_clk_get_pllsai_rate(priv, PLLSAIP); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 455 | else |
Patrice Chotard | 8aca2d1 | 2018-02-08 17:20:48 +0100 | [diff] [blame] | 456 | return (vco / pllq); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 457 | break; |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 458 | |
| 459 | /* For timer clock, an additionnal prescaler is used*/ |
| 460 | case STM32F7_APB2_CLOCK(TIM1): |
| 461 | case STM32F7_APB2_CLOCK(TIM8): |
| 462 | case STM32F7_APB2_CLOCK(TIM9): |
| 463 | case STM32F7_APB2_CLOCK(TIM10): |
| 464 | case STM32F7_APB2_CLOCK(TIM11): |
| 465 | return stm32_get_timer_rate(priv, sysclk, APB2); |
| 466 | break; |
Patrice Chotard | ff7b11e | 2018-02-08 17:20:49 +0100 | [diff] [blame^] | 467 | |
| 468 | /* particular case for LTDC clock */ |
| 469 | case STM32F7_APB2_CLOCK(LTDC): |
| 470 | saidivr = readl(®s->dckcfgr); |
| 471 | saidivr = (saidivr & RCC_DCKCFGR_PLLSAIDIVR_MASK) |
| 472 | >> RCC_DCKCFGR_PLLSAIDIVR_SHIFT; |
| 473 | pllsai_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR); |
| 474 | |
| 475 | return pllsai_rate / pllsaidivr_table[saidivr]; |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 476 | } |
Patrice Chotard | ef77287 | 2018-02-07 10:44:46 +0100 | [diff] [blame] | 477 | return (sysclk >> stm32_get_apb_shift(regs, APB2)); |
Patrice Chotard | 369d483 | 2017-11-15 13:14:52 +0100 | [diff] [blame] | 478 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 479 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 480 | pr_err("clock index %ld out of range\n", clk->id); |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 481 | return -EINVAL; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
Patrice Chotard | 24e8578 | 2018-01-29 18:14:14 +0100 | [diff] [blame] | 485 | static ulong stm32_set_rate(struct clk *clk, ulong rate) |
| 486 | { |
| 487 | return 0; |
| 488 | } |
| 489 | |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 490 | static int stm32_clk_enable(struct clk *clk) |
| 491 | { |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 492 | struct stm32_clk *priv = dev_get_priv(clk->dev); |
| 493 | struct stm32_rcc_regs *regs = priv->base; |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 494 | u32 offset = clk->id / 32; |
| 495 | u32 bit_index = clk->id % 32; |
| 496 | |
| 497 | debug("%s: clkid = %ld, offset from AHB1ENR is %d, bit_index = %d\n", |
| 498 | __func__, clk->id, offset, bit_index); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 499 | setbits_le32(®s->ahb1enr + offset, BIT(bit_index)); |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 500 | |
| 501 | return 0; |
| 502 | } |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 503 | |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 504 | static int stm32_clk_probe(struct udevice *dev) |
| 505 | { |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 506 | struct ofnode_phandle_args args; |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 507 | struct udevice *fixed_clock_dev = NULL; |
| 508 | struct clk clk; |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 509 | int err; |
| 510 | |
Patrice Chotard | d4f2d20 | 2017-11-15 13:14:48 +0100 | [diff] [blame] | 511 | debug("%s\n", __func__); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 512 | |
| 513 | struct stm32_clk *priv = dev_get_priv(dev); |
| 514 | fdt_addr_t addr; |
| 515 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 516 | addr = dev_read_addr(dev); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 517 | if (addr == FDT_ADDR_T_NONE) |
| 518 | return -EINVAL; |
| 519 | |
| 520 | priv->base = (struct stm32_rcc_regs *)addr; |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 521 | |
| 522 | switch (dev_get_driver_data(dev)) { |
| 523 | case STM32F4: |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 524 | memcpy(&priv->info, &stm32f4_clk_info, |
| 525 | sizeof(struct stm32_clk_info)); |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 526 | break; |
| 527 | case STM32F7: |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 528 | memcpy(&priv->info, &stm32f7_clk_info, |
| 529 | sizeof(struct stm32_clk_info)); |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 530 | break; |
| 531 | default: |
| 532 | return -EINVAL; |
| 533 | } |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 534 | |
Patrice Chotard | acd97ca | 2018-01-18 13:39:30 +0100 | [diff] [blame] | 535 | /* retrieve HSE frequency (external oscillator) */ |
| 536 | err = uclass_get_device_by_name(UCLASS_CLK, "clk-hse", |
| 537 | &fixed_clock_dev); |
| 538 | |
| 539 | if (err) { |
| 540 | pr_err("Can't find fixed clock (%d)", err); |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | err = clk_request(fixed_clock_dev, &clk); |
| 545 | if (err) { |
| 546 | pr_err("Can't request %s clk (%d)", fixed_clock_dev->name, |
| 547 | err); |
| 548 | return err; |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * set pllm factor accordingly to the external oscillator |
| 553 | * frequency (HSE). For STM32F4 and STM32F7, we want VCO |
| 554 | * freq at 1MHz |
| 555 | * if input PLL frequency is 25Mhz, divide it by 25 |
| 556 | */ |
| 557 | clk.id = 0; |
| 558 | priv->hse_rate = clk_get_rate(&clk); |
| 559 | |
| 560 | if (priv->hse_rate < 1000000) { |
| 561 | pr_err("%s: unexpected HSE clock rate = %ld \"n", __func__, |
| 562 | priv->hse_rate); |
| 563 | return -EINVAL; |
| 564 | } |
| 565 | |
| 566 | priv->info.sys_pll_psc.pll_m = priv->hse_rate / 1000000; |
| 567 | |
| 568 | if (priv->info.has_overdrive) { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 569 | err = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0, |
| 570 | &args); |
| 571 | if (err) { |
| 572 | debug("%s: can't find syscon device (%d)\n", __func__, |
| 573 | err); |
| 574 | return err; |
| 575 | } |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 576 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 577 | priv->pwr_regs = (struct stm32_pwr_regs *)ofnode_get_addr(args.node); |
| 578 | } |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 579 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 580 | configure_clocks(dev); |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 585 | static int stm32_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 586 | { |
| 587 | debug("%s(clk=%p)\n", __func__, clk); |
| 588 | |
| 589 | if (args->args_count != 2) { |
| 590 | debug("Invaild args_count: %d\n", args->args_count); |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
| 594 | if (args->args_count) |
| 595 | clk->id = args->args[1]; |
| 596 | else |
| 597 | clk->id = 0; |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static struct clk_ops stm32_clk_ops = { |
| 603 | .of_xlate = stm32_clk_of_xlate, |
| 604 | .enable = stm32_clk_enable, |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 605 | .get_rate = stm32_clk_get_rate, |
Patrice Chotard | 24e8578 | 2018-01-29 18:14:14 +0100 | [diff] [blame] | 606 | .set_rate = stm32_set_rate, |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 607 | }; |
| 608 | |
Patrice Chotard | d4f2d20 | 2017-11-15 13:14:48 +0100 | [diff] [blame] | 609 | U_BOOT_DRIVER(stm32fx_clk) = { |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 610 | .name = "stm32fx_rcc_clock", |
Patrice Chotard | b323de5 | 2017-09-21 10:08:09 +0200 | [diff] [blame] | 611 | .id = UCLASS_CLK, |
Patrice Chotard | b323de5 | 2017-09-21 10:08:09 +0200 | [diff] [blame] | 612 | .ops = &stm32_clk_ops, |
| 613 | .probe = stm32_clk_probe, |
| 614 | .priv_auto_alloc_size = sizeof(struct stm32_clk), |
| 615 | .flags = DM_FLAG_PRE_RELOC, |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 616 | }; |