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