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 | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 11 | |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/rcc.h> |
| 14 | #include <asm/arch/stm32.h> |
| 15 | #include <asm/arch/stm32_periph.h> |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 16 | #include <asm/arch/stm32_pwr.h> |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 17 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 18 | #include <dt-bindings/mfd/stm32f7-rcc.h> |
| 19 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 20 | #define RCC_CR_HSION BIT(0) |
| 21 | #define RCC_CR_HSEON BIT(16) |
| 22 | #define RCC_CR_HSERDY BIT(17) |
| 23 | #define RCC_CR_HSEBYP BIT(18) |
| 24 | #define RCC_CR_CSSON BIT(19) |
| 25 | #define RCC_CR_PLLON BIT(24) |
| 26 | #define RCC_CR_PLLRDY BIT(25) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 27 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 28 | #define RCC_PLLCFGR_PLLM_MASK GENMASK(5, 0) |
| 29 | #define RCC_PLLCFGR_PLLN_MASK GENMASK(14, 6) |
| 30 | #define RCC_PLLCFGR_PLLP_MASK GENMASK(17, 16) |
| 31 | #define RCC_PLLCFGR_PLLQ_MASK GENMASK(27, 24) |
| 32 | #define RCC_PLLCFGR_PLLSRC BIT(22) |
| 33 | #define RCC_PLLCFGR_PLLM_SHIFT 0 |
| 34 | #define RCC_PLLCFGR_PLLN_SHIFT 6 |
| 35 | #define RCC_PLLCFGR_PLLP_SHIFT 16 |
| 36 | #define RCC_PLLCFGR_PLLQ_SHIFT 24 |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 37 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 38 | #define RCC_CFGR_AHB_PSC_MASK GENMASK(7, 4) |
| 39 | #define RCC_CFGR_APB1_PSC_MASK GENMASK(12, 10) |
| 40 | #define RCC_CFGR_APB2_PSC_MASK GENMASK(15, 13) |
| 41 | #define RCC_CFGR_SW0 BIT(0) |
| 42 | #define RCC_CFGR_SW1 BIT(1) |
| 43 | #define RCC_CFGR_SW_MASK GENMASK(1, 0) |
| 44 | #define RCC_CFGR_SW_HSI 0 |
| 45 | #define RCC_CFGR_SW_HSE RCC_CFGR_SW0 |
| 46 | #define RCC_CFGR_SW_PLL RCC_CFGR_SW1 |
| 47 | #define RCC_CFGR_SWS0 BIT(2) |
| 48 | #define RCC_CFGR_SWS1 BIT(3) |
| 49 | #define RCC_CFGR_SWS_MASK GENMASK(3, 2) |
| 50 | #define RCC_CFGR_SWS_HSI 0 |
| 51 | #define RCC_CFGR_SWS_HSE RCC_CFGR_SWS0 |
| 52 | #define RCC_CFGR_SWS_PLL RCC_CFGR_SWS1 |
| 53 | #define RCC_CFGR_HPRE_SHIFT 4 |
| 54 | #define RCC_CFGR_PPRE1_SHIFT 10 |
| 55 | #define RCC_CFGR_PPRE2_SHIFT 13 |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 56 | |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 57 | |
| 58 | struct pll_psc { |
| 59 | u8 pll_m; |
| 60 | u16 pll_n; |
| 61 | u8 pll_p; |
| 62 | u8 pll_q; |
| 63 | u8 ahb_psc; |
| 64 | u8 apb1_psc; |
| 65 | u8 apb2_psc; |
| 66 | }; |
| 67 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 68 | #define AHB_PSC_1 0 |
| 69 | #define AHB_PSC_2 0x8 |
| 70 | #define AHB_PSC_4 0x9 |
| 71 | #define AHB_PSC_8 0xA |
| 72 | #define AHB_PSC_16 0xB |
| 73 | #define AHB_PSC_64 0xC |
| 74 | #define AHB_PSC_128 0xD |
| 75 | #define AHB_PSC_256 0xE |
| 76 | #define AHB_PSC_512 0xF |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 77 | |
Michael Kurz | c204fb7 | 2017-01-22 16:04:24 +0100 | [diff] [blame] | 78 | #define APB_PSC_1 0 |
| 79 | #define APB_PSC_2 0x4 |
| 80 | #define APB_PSC_4 0x5 |
| 81 | #define APB_PSC_8 0x6 |
| 82 | #define APB_PSC_16 0x7 |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 83 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 84 | struct stm32_clk_info { |
| 85 | struct pll_psc sys_pll_psc; |
| 86 | bool has_overdrive; |
| 87 | }; |
| 88 | |
| 89 | struct stm32_clk_info stm32f4_clk_info = { |
| 90 | /* 180 MHz */ |
| 91 | .sys_pll_psc = { |
| 92 | .pll_m = 8, |
| 93 | .pll_n = 360, |
| 94 | .pll_p = 2, |
| 95 | .pll_q = 8, |
| 96 | .ahb_psc = AHB_PSC_1, |
| 97 | .apb1_psc = APB_PSC_4, |
| 98 | .apb2_psc = APB_PSC_2, |
| 99 | }, |
| 100 | .has_overdrive = false, |
| 101 | }; |
| 102 | |
| 103 | struct stm32_clk_info stm32f7_clk_info = { |
| 104 | /* 200 MHz */ |
| 105 | .sys_pll_psc = { |
| 106 | .pll_m = 25, |
| 107 | .pll_n = 400, |
| 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 = true, |
| 115 | }; |
| 116 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 117 | struct stm32_clk { |
| 118 | struct stm32_rcc_regs *base; |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 119 | struct stm32_pwr_regs *pwr_regs; |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 120 | struct stm32_clk_info *info; |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 121 | }; |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 122 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 123 | static int configure_clocks(struct udevice *dev) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 124 | { |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 125 | struct stm32_clk *priv = dev_get_priv(dev); |
| 126 | struct stm32_rcc_regs *regs = priv->base; |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 127 | struct stm32_pwr_regs *pwr = priv->pwr_regs; |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 128 | struct pll_psc sys_pll_psc = priv->info->sys_pll_psc; |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 129 | |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 130 | /* Reset RCC configuration */ |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 131 | setbits_le32(®s->cr, RCC_CR_HSION); |
| 132 | writel(0, ®s->cfgr); /* Reset CFGR */ |
| 133 | clrbits_le32(®s->cr, (RCC_CR_HSEON | RCC_CR_CSSON |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 134 | | RCC_CR_PLLON)); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 135 | writel(0x24003010, ®s->pllcfgr); /* Reset value from RM */ |
| 136 | clrbits_le32(®s->cr, RCC_CR_HSEBYP); |
| 137 | writel(0, ®s->cir); /* Disable all interrupts */ |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 138 | |
| 139 | /* Configure for HSE+PLL operation */ |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 140 | setbits_le32(®s->cr, RCC_CR_HSEON); |
| 141 | while (!(readl(®s->cr) & RCC_CR_HSERDY)) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 142 | ; |
| 143 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 144 | setbits_le32(®s->cfgr, (( |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 145 | sys_pll_psc.ahb_psc << RCC_CFGR_HPRE_SHIFT) |
| 146 | | (sys_pll_psc.apb1_psc << RCC_CFGR_PPRE1_SHIFT) |
| 147 | | (sys_pll_psc.apb2_psc << RCC_CFGR_PPRE2_SHIFT))); |
| 148 | |
| 149 | /* Configure the main PLL */ |
Patrice Chotard | b6653f6 | 2017-10-26 13:23:19 +0200 | [diff] [blame] | 150 | setbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLSRC); /* pll source HSE */ |
| 151 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLM_MASK, |
| 152 | sys_pll_psc.pll_m << RCC_PLLCFGR_PLLM_SHIFT); |
| 153 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLN_MASK, |
| 154 | sys_pll_psc.pll_n << RCC_PLLCFGR_PLLN_SHIFT); |
| 155 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLP_MASK, |
| 156 | ((sys_pll_psc.pll_p >> 1) - 1) << RCC_PLLCFGR_PLLP_SHIFT); |
| 157 | clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLQ_MASK, |
| 158 | sys_pll_psc.pll_q << RCC_PLLCFGR_PLLQ_SHIFT); |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 159 | |
| 160 | /* Enable the main PLL */ |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 161 | setbits_le32(®s->cr, RCC_CR_PLLON); |
| 162 | while (!(readl(®s->cr) & RCC_CR_PLLRDY)) |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 163 | ; |
| 164 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 165 | setbits_le32(®s->apb1enr, RCC_APB1ENR_PWREN); |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 166 | |
| 167 | if (priv->info->has_overdrive) { |
| 168 | /* |
| 169 | * Enable high performance mode |
| 170 | * System frequency up to 200 MHz |
| 171 | */ |
| 172 | setbits_le32(&pwr->cr1, PWR_CR1_ODEN); |
| 173 | /* Infinite wait! */ |
| 174 | while (!(readl(&pwr->csr1) & PWR_CSR1_ODRDY)) |
| 175 | ; |
| 176 | /* Enable the Over-drive switch */ |
| 177 | setbits_le32(&pwr->cr1, PWR_CR1_ODSWEN); |
| 178 | /* Infinite wait! */ |
| 179 | while (!(readl(&pwr->csr1) & PWR_CSR1_ODSWRDY)) |
| 180 | ; |
| 181 | } |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 182 | |
| 183 | stm32_flash_latency_cfg(5); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 184 | clrbits_le32(®s->cfgr, (RCC_CFGR_SW0 | RCC_CFGR_SW1)); |
| 185 | setbits_le32(®s->cfgr, RCC_CFGR_SW_PLL); |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 186 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 187 | while ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) != |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 188 | RCC_CFGR_SWS_PLL) |
| 189 | ; |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 194 | static unsigned long stm32_clk_get_rate(struct clk *clk) |
| 195 | { |
| 196 | struct stm32_clk *priv = dev_get_priv(clk->dev); |
| 197 | struct stm32_rcc_regs *regs = priv->base; |
| 198 | u32 sysclk = 0; |
| 199 | u32 shift = 0; |
Patrice Chotard | d4f2d20 | 2017-11-15 13:14:48 +0100 | [diff] [blame^] | 200 | u16 pllm, plln, pllp; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 201 | /* Prescaler table lookups for clock computation */ |
| 202 | u8 ahb_psc_table[16] = { |
| 203 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9 |
| 204 | }; |
| 205 | u8 apb_psc_table[8] = { |
| 206 | 0, 0, 0, 0, 1, 2, 3, 4 |
| 207 | }; |
| 208 | |
| 209 | if ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) == |
| 210 | RCC_CFGR_SWS_PLL) { |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 211 | pllm = (readl(®s->pllcfgr) & RCC_PLLCFGR_PLLM_MASK); |
| 212 | plln = ((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLN_MASK) |
| 213 | >> RCC_PLLCFGR_PLLN_SHIFT); |
| 214 | pllp = ((((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLP_MASK) |
| 215 | >> RCC_PLLCFGR_PLLP_SHIFT) + 1) << 1); |
| 216 | sysclk = ((CONFIG_STM32_HSE_HZ / pllm) * plln) / pllp; |
| 217 | } else { |
| 218 | return -EINVAL; |
| 219 | } |
| 220 | |
| 221 | switch (clk->id) { |
| 222 | /* |
| 223 | * AHB CLOCK: 3 x 32 bits consecutive registers are used : |
| 224 | * AHB1, AHB2 and AHB3 |
| 225 | */ |
| 226 | case STM32F7_AHB1_CLOCK(GPIOA) ... STM32F7_AHB3_CLOCK(QSPI): |
| 227 | shift = ahb_psc_table[( |
| 228 | (readl(®s->cfgr) & RCC_CFGR_AHB_PSC_MASK) |
| 229 | >> RCC_CFGR_HPRE_SHIFT)]; |
| 230 | return sysclk >>= shift; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 231 | /* APB1 CLOCK */ |
| 232 | case STM32F7_APB1_CLOCK(TIM2) ... STM32F7_APB1_CLOCK(UART8): |
| 233 | shift = apb_psc_table[( |
| 234 | (readl(®s->cfgr) & RCC_CFGR_APB1_PSC_MASK) |
| 235 | >> RCC_CFGR_PPRE1_SHIFT)]; |
| 236 | return sysclk >>= shift; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 237 | /* APB2 CLOCK */ |
| 238 | case STM32F7_APB2_CLOCK(TIM1) ... STM32F7_APB2_CLOCK(LTDC): |
| 239 | shift = apb_psc_table[( |
| 240 | (readl(®s->cfgr) & RCC_CFGR_APB2_PSC_MASK) |
| 241 | >> RCC_CFGR_PPRE2_SHIFT)]; |
| 242 | return sysclk >>= shift; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 243 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 244 | pr_err("clock index %ld out of range\n", clk->id); |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 245 | return -EINVAL; |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 249 | static int stm32_clk_enable(struct clk *clk) |
| 250 | { |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 251 | struct stm32_clk *priv = dev_get_priv(clk->dev); |
| 252 | struct stm32_rcc_regs *regs = priv->base; |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 253 | u32 offset = clk->id / 32; |
| 254 | u32 bit_index = clk->id % 32; |
| 255 | |
| 256 | debug("%s: clkid = %ld, offset from AHB1ENR is %d, bit_index = %d\n", |
| 257 | __func__, clk->id, offset, bit_index); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 258 | setbits_le32(®s->ahb1enr + offset, BIT(bit_index)); |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 259 | |
| 260 | return 0; |
| 261 | } |
Toshifumi NISHINAGA | 65bfb9c | 2016-07-08 01:02:24 +0900 | [diff] [blame] | 262 | |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 263 | void clock_setup(int peripheral) |
| 264 | { |
| 265 | switch (peripheral) { |
Michael Kurz | 04bb8db | 2017-01-22 16:04:26 +0100 | [diff] [blame] | 266 | case SYSCFG_CLOCK_CFG: |
| 267 | setbits_le32(&STM32_RCC->apb2enr, RCC_APB2ENR_SYSCFGEN); |
| 268 | break; |
| 269 | case TIMER2_CLOCK_CFG: |
| 270 | setbits_le32(&STM32_RCC->apb1enr, RCC_APB1ENR_TIM2EN); |
| 271 | break; |
Michael Kurz | 812962b | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 272 | case STMMAC_CLOCK_CFG: |
| 273 | setbits_le32(&STM32_RCC->ahb1enr, RCC_AHB1ENR_ETHMAC_EN); |
| 274 | setbits_le32(&STM32_RCC->ahb1enr, RCC_AHB1ENR_ETHMAC_RX_EN); |
| 275 | setbits_le32(&STM32_RCC->ahb1enr, RCC_AHB1ENR_ETHMAC_TX_EN); |
| 276 | break; |
Vikas Manocha | 1b51c93 | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 277 | default: |
| 278 | break; |
| 279 | } |
| 280 | } |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 281 | |
| 282 | static int stm32_clk_probe(struct udevice *dev) |
| 283 | { |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 284 | struct ofnode_phandle_args args; |
| 285 | int err; |
| 286 | |
Patrice Chotard | d4f2d20 | 2017-11-15 13:14:48 +0100 | [diff] [blame^] | 287 | debug("%s\n", __func__); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 288 | |
| 289 | struct stm32_clk *priv = dev_get_priv(dev); |
| 290 | fdt_addr_t addr; |
| 291 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 292 | addr = dev_read_addr(dev); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 293 | if (addr == FDT_ADDR_T_NONE) |
| 294 | return -EINVAL; |
| 295 | |
| 296 | priv->base = (struct stm32_rcc_regs *)addr; |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 297 | priv->info = (struct stm32_clk_info *)dev_get_driver_data(dev); |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 298 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 299 | if (priv->info->has_overdrive) { |
| 300 | err = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0, |
| 301 | &args); |
| 302 | if (err) { |
| 303 | debug("%s: can't find syscon device (%d)\n", __func__, |
| 304 | err); |
| 305 | return err; |
| 306 | } |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 307 | |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 308 | priv->pwr_regs = (struct stm32_pwr_regs *)ofnode_get_addr(args.node); |
| 309 | } |
Patrice Chotard | 22768d5 | 2017-11-15 13:14:44 +0100 | [diff] [blame] | 310 | |
Patrice Chotard | d93fc2c | 2017-07-18 09:29:04 +0200 | [diff] [blame] | 311 | configure_clocks(dev); |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 316 | 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] | 317 | { |
| 318 | debug("%s(clk=%p)\n", __func__, clk); |
| 319 | |
| 320 | if (args->args_count != 2) { |
| 321 | debug("Invaild args_count: %d\n", args->args_count); |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
| 325 | if (args->args_count) |
| 326 | clk->id = args->args[1]; |
| 327 | else |
| 328 | clk->id = 0; |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static struct clk_ops stm32_clk_ops = { |
| 334 | .of_xlate = stm32_clk_of_xlate, |
| 335 | .enable = stm32_clk_enable, |
Patrice Chotard | 7bdf971 | 2017-07-18 09:29:05 +0200 | [diff] [blame] | 336 | .get_rate = stm32_clk_get_rate, |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | static const struct udevice_id stm32_clk_ids[] = { |
Patrice Chotard | 1509d66 | 2017-11-15 13:14:47 +0100 | [diff] [blame] | 340 | { .compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32f4_clk_info}, |
| 341 | { .compatible = "st,stm32f746-rcc", .data = (ulong)&stm32f7_clk_info}, |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 342 | {} |
| 343 | }; |
| 344 | |
Patrice Chotard | d4f2d20 | 2017-11-15 13:14:48 +0100 | [diff] [blame^] | 345 | U_BOOT_DRIVER(stm32fx_clk) = { |
| 346 | .name = "stm32fx_clk", |
Patrice Chotard | b323de5 | 2017-09-21 10:08:09 +0200 | [diff] [blame] | 347 | .id = UCLASS_CLK, |
| 348 | .of_match = stm32_clk_ids, |
| 349 | .ops = &stm32_clk_ops, |
| 350 | .probe = stm32_clk_probe, |
| 351 | .priv_auto_alloc_size = sizeof(struct stm32_clk), |
| 352 | .flags = DM_FLAG_PRE_RELOC, |
Vikas Manocha | daaeaab | 2017-02-12 10:25:45 -0800 | [diff] [blame] | 353 | }; |