18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) STMicroelectronics 2018 - All Rights Reserved 48c2ecf20Sopenharmony_ci * Author: Olivier Bideau <olivier.bideau@st.com> for STMicroelectronics. 58c2ecf20Sopenharmony_ci * Author: Gabriel Fernandez <gabriel.fernandez@st.com> for STMicroelectronics. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/clk.h> 98c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/err.h> 128c2ecf20Sopenharmony_ci#include <linux/io.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/of_address.h> 158c2ecf20Sopenharmony_ci#include <linux/slab.h> 168c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <dt-bindings/clock/stm32mp1-clks.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(rlock); 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define RCC_OCENSETR 0x0C 238c2ecf20Sopenharmony_ci#define RCC_HSICFGR 0x18 248c2ecf20Sopenharmony_ci#define RCC_RDLSICR 0x144 258c2ecf20Sopenharmony_ci#define RCC_PLL1CR 0x80 268c2ecf20Sopenharmony_ci#define RCC_PLL1CFGR1 0x84 278c2ecf20Sopenharmony_ci#define RCC_PLL1CFGR2 0x88 288c2ecf20Sopenharmony_ci#define RCC_PLL2CR 0x94 298c2ecf20Sopenharmony_ci#define RCC_PLL2CFGR1 0x98 308c2ecf20Sopenharmony_ci#define RCC_PLL2CFGR2 0x9C 318c2ecf20Sopenharmony_ci#define RCC_PLL3CR 0x880 328c2ecf20Sopenharmony_ci#define RCC_PLL3CFGR1 0x884 338c2ecf20Sopenharmony_ci#define RCC_PLL3CFGR2 0x888 348c2ecf20Sopenharmony_ci#define RCC_PLL4CR 0x894 358c2ecf20Sopenharmony_ci#define RCC_PLL4CFGR1 0x898 368c2ecf20Sopenharmony_ci#define RCC_PLL4CFGR2 0x89C 378c2ecf20Sopenharmony_ci#define RCC_APB1ENSETR 0xA00 388c2ecf20Sopenharmony_ci#define RCC_APB2ENSETR 0xA08 398c2ecf20Sopenharmony_ci#define RCC_APB3ENSETR 0xA10 408c2ecf20Sopenharmony_ci#define RCC_APB4ENSETR 0x200 418c2ecf20Sopenharmony_ci#define RCC_APB5ENSETR 0x208 428c2ecf20Sopenharmony_ci#define RCC_AHB2ENSETR 0xA18 438c2ecf20Sopenharmony_ci#define RCC_AHB3ENSETR 0xA20 448c2ecf20Sopenharmony_ci#define RCC_AHB4ENSETR 0xA28 458c2ecf20Sopenharmony_ci#define RCC_AHB5ENSETR 0x210 468c2ecf20Sopenharmony_ci#define RCC_AHB6ENSETR 0x218 478c2ecf20Sopenharmony_ci#define RCC_AHB6LPENSETR 0x318 488c2ecf20Sopenharmony_ci#define RCC_RCK12SELR 0x28 498c2ecf20Sopenharmony_ci#define RCC_RCK3SELR 0x820 508c2ecf20Sopenharmony_ci#define RCC_RCK4SELR 0x824 518c2ecf20Sopenharmony_ci#define RCC_MPCKSELR 0x20 528c2ecf20Sopenharmony_ci#define RCC_ASSCKSELR 0x24 538c2ecf20Sopenharmony_ci#define RCC_MSSCKSELR 0x48 548c2ecf20Sopenharmony_ci#define RCC_SPI6CKSELR 0xC4 558c2ecf20Sopenharmony_ci#define RCC_SDMMC12CKSELR 0x8F4 568c2ecf20Sopenharmony_ci#define RCC_SDMMC3CKSELR 0x8F8 578c2ecf20Sopenharmony_ci#define RCC_FMCCKSELR 0x904 588c2ecf20Sopenharmony_ci#define RCC_I2C46CKSELR 0xC0 598c2ecf20Sopenharmony_ci#define RCC_I2C12CKSELR 0x8C0 608c2ecf20Sopenharmony_ci#define RCC_I2C35CKSELR 0x8C4 618c2ecf20Sopenharmony_ci#define RCC_UART1CKSELR 0xC8 628c2ecf20Sopenharmony_ci#define RCC_QSPICKSELR 0x900 638c2ecf20Sopenharmony_ci#define RCC_ETHCKSELR 0x8FC 648c2ecf20Sopenharmony_ci#define RCC_RNG1CKSELR 0xCC 658c2ecf20Sopenharmony_ci#define RCC_RNG2CKSELR 0x920 668c2ecf20Sopenharmony_ci#define RCC_GPUCKSELR 0x938 678c2ecf20Sopenharmony_ci#define RCC_USBCKSELR 0x91C 688c2ecf20Sopenharmony_ci#define RCC_STGENCKSELR 0xD4 698c2ecf20Sopenharmony_ci#define RCC_SPDIFCKSELR 0x914 708c2ecf20Sopenharmony_ci#define RCC_SPI2S1CKSELR 0x8D8 718c2ecf20Sopenharmony_ci#define RCC_SPI2S23CKSELR 0x8DC 728c2ecf20Sopenharmony_ci#define RCC_SPI2S45CKSELR 0x8E0 738c2ecf20Sopenharmony_ci#define RCC_CECCKSELR 0x918 748c2ecf20Sopenharmony_ci#define RCC_LPTIM1CKSELR 0x934 758c2ecf20Sopenharmony_ci#define RCC_LPTIM23CKSELR 0x930 768c2ecf20Sopenharmony_ci#define RCC_LPTIM45CKSELR 0x92C 778c2ecf20Sopenharmony_ci#define RCC_UART24CKSELR 0x8E8 788c2ecf20Sopenharmony_ci#define RCC_UART35CKSELR 0x8EC 798c2ecf20Sopenharmony_ci#define RCC_UART6CKSELR 0x8E4 808c2ecf20Sopenharmony_ci#define RCC_UART78CKSELR 0x8F0 818c2ecf20Sopenharmony_ci#define RCC_FDCANCKSELR 0x90C 828c2ecf20Sopenharmony_ci#define RCC_SAI1CKSELR 0x8C8 838c2ecf20Sopenharmony_ci#define RCC_SAI2CKSELR 0x8CC 848c2ecf20Sopenharmony_ci#define RCC_SAI3CKSELR 0x8D0 858c2ecf20Sopenharmony_ci#define RCC_SAI4CKSELR 0x8D4 868c2ecf20Sopenharmony_ci#define RCC_ADCCKSELR 0x928 878c2ecf20Sopenharmony_ci#define RCC_MPCKDIVR 0x2C 888c2ecf20Sopenharmony_ci#define RCC_DSICKSELR 0x924 898c2ecf20Sopenharmony_ci#define RCC_CPERCKSELR 0xD0 908c2ecf20Sopenharmony_ci#define RCC_MCO1CFGR 0x800 918c2ecf20Sopenharmony_ci#define RCC_MCO2CFGR 0x804 928c2ecf20Sopenharmony_ci#define RCC_BDCR 0x140 938c2ecf20Sopenharmony_ci#define RCC_AXIDIVR 0x30 948c2ecf20Sopenharmony_ci#define RCC_MCUDIVR 0x830 958c2ecf20Sopenharmony_ci#define RCC_APB1DIVR 0x834 968c2ecf20Sopenharmony_ci#define RCC_APB2DIVR 0x838 978c2ecf20Sopenharmony_ci#define RCC_APB3DIVR 0x83C 988c2ecf20Sopenharmony_ci#define RCC_APB4DIVR 0x3C 998c2ecf20Sopenharmony_ci#define RCC_APB5DIVR 0x40 1008c2ecf20Sopenharmony_ci#define RCC_TIMG1PRER 0x828 1018c2ecf20Sopenharmony_ci#define RCC_TIMG2PRER 0x82C 1028c2ecf20Sopenharmony_ci#define RCC_RTCDIVR 0x44 1038c2ecf20Sopenharmony_ci#define RCC_DBGCFGR 0x80C 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define RCC_CLR 0x4 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const char * const ref12_parents[] = { 1088c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse" 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistatic const char * const ref3_parents[] = { 1128c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "ck_csi" 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic const char * const ref4_parents[] = { 1168c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "ck_csi" 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic const char * const cpu_src[] = { 1208c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "pll1_p" 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic const char * const axi_src[] = { 1248c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "pll2_p" 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic const char * const per_src[] = { 1288c2ecf20Sopenharmony_ci "ck_hsi", "ck_csi", "ck_hse" 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic const char * const mcu_src[] = { 1328c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "ck_csi", "pll3_p" 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic const char * const sdmmc12_src[] = { 1368c2ecf20Sopenharmony_ci "ck_axi", "pll3_r", "pll4_p", "ck_hsi" 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic const char * const sdmmc3_src[] = { 1408c2ecf20Sopenharmony_ci "ck_mcu", "pll3_r", "pll4_p", "ck_hsi" 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic const char * const fmc_src[] = { 1448c2ecf20Sopenharmony_ci "ck_axi", "pll3_r", "pll4_p", "ck_per" 1458c2ecf20Sopenharmony_ci}; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic const char * const qspi_src[] = { 1488c2ecf20Sopenharmony_ci "ck_axi", "pll3_r", "pll4_p", "ck_per" 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic const char * const eth_src[] = { 1528c2ecf20Sopenharmony_ci "pll4_p", "pll3_q" 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic const char * const rng_src[] = { 1568c2ecf20Sopenharmony_ci "ck_csi", "pll4_r", "ck_lse", "ck_lsi" 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic const char * const usbphy_src[] = { 1608c2ecf20Sopenharmony_ci "ck_hse", "pll4_r", "clk-hse-div2" 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic const char * const usbo_src[] = { 1648c2ecf20Sopenharmony_ci "pll4_r", "ck_usbo_48m" 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic const char * const stgen_src[] = { 1688c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse" 1698c2ecf20Sopenharmony_ci}; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic const char * const spdif_src[] = { 1728c2ecf20Sopenharmony_ci "pll4_p", "pll3_q", "ck_hsi" 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic const char * const spi123_src[] = { 1768c2ecf20Sopenharmony_ci "pll4_p", "pll3_q", "i2s_ckin", "ck_per", "pll3_r" 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic const char * const spi45_src[] = { 1808c2ecf20Sopenharmony_ci "pclk2", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic const char * const spi6_src[] = { 1848c2ecf20Sopenharmony_ci "pclk5", "pll4_q", "ck_hsi", "ck_csi", "ck_hse", "pll3_q" 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic const char * const cec_src[] = { 1888c2ecf20Sopenharmony_ci "ck_lse", "ck_lsi", "ck_csi" 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic const char * const i2c12_src[] = { 1928c2ecf20Sopenharmony_ci "pclk1", "pll4_r", "ck_hsi", "ck_csi" 1938c2ecf20Sopenharmony_ci}; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic const char * const i2c35_src[] = { 1968c2ecf20Sopenharmony_ci "pclk1", "pll4_r", "ck_hsi", "ck_csi" 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistatic const char * const i2c46_src[] = { 2008c2ecf20Sopenharmony_ci "pclk5", "pll3_q", "ck_hsi", "ck_csi" 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic const char * const lptim1_src[] = { 2048c2ecf20Sopenharmony_ci "pclk1", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per" 2058c2ecf20Sopenharmony_ci}; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cistatic const char * const lptim23_src[] = { 2088c2ecf20Sopenharmony_ci "pclk3", "pll4_q", "ck_per", "ck_lse", "ck_lsi" 2098c2ecf20Sopenharmony_ci}; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistatic const char * const lptim45_src[] = { 2128c2ecf20Sopenharmony_ci "pclk3", "pll4_p", "pll3_q", "ck_lse", "ck_lsi", "ck_per" 2138c2ecf20Sopenharmony_ci}; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic const char * const usart1_src[] = { 2168c2ecf20Sopenharmony_ci "pclk5", "pll3_q", "ck_hsi", "ck_csi", "pll4_q", "ck_hse" 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic const char * const usart234578_src[] = { 2208c2ecf20Sopenharmony_ci "pclk1", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" 2218c2ecf20Sopenharmony_ci}; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic const char * const usart6_src[] = { 2248c2ecf20Sopenharmony_ci "pclk2", "pll4_q", "ck_hsi", "ck_csi", "ck_hse" 2258c2ecf20Sopenharmony_ci}; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic const char * const fdcan_src[] = { 2288c2ecf20Sopenharmony_ci "ck_hse", "pll3_q", "pll4_q", "pll4_r" 2298c2ecf20Sopenharmony_ci}; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cistatic const char * const sai_src[] = { 2328c2ecf20Sopenharmony_ci "pll4_q", "pll3_q", "i2s_ckin", "ck_per", "pll3_r" 2338c2ecf20Sopenharmony_ci}; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistatic const char * const sai2_src[] = { 2368c2ecf20Sopenharmony_ci "pll4_q", "pll3_q", "i2s_ckin", "ck_per", "spdif_ck_symb", "pll3_r" 2378c2ecf20Sopenharmony_ci}; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic const char * const adc12_src[] = { 2408c2ecf20Sopenharmony_ci "pll4_r", "ck_per", "pll3_q" 2418c2ecf20Sopenharmony_ci}; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic const char * const dsi_src[] = { 2448c2ecf20Sopenharmony_ci "ck_dsi_phy", "pll4_p" 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistatic const char * const rtc_src[] = { 2488c2ecf20Sopenharmony_ci "off", "ck_lse", "ck_lsi", "ck_hse_rtc" 2498c2ecf20Sopenharmony_ci}; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_cistatic const char * const mco1_src[] = { 2528c2ecf20Sopenharmony_ci "ck_hsi", "ck_hse", "ck_csi", "ck_lsi", "ck_lse" 2538c2ecf20Sopenharmony_ci}; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_cistatic const char * const mco2_src[] = { 2568c2ecf20Sopenharmony_ci "ck_mpu", "ck_axi", "ck_mcu", "pll4_p", "ck_hse", "ck_hsi" 2578c2ecf20Sopenharmony_ci}; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic const char * const ck_trace_src[] = { 2608c2ecf20Sopenharmony_ci "ck_axi" 2618c2ecf20Sopenharmony_ci}; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic const struct clk_div_table axi_div_table[] = { 2648c2ecf20Sopenharmony_ci { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 4 }, 2658c2ecf20Sopenharmony_ci { 4, 4 }, { 5, 4 }, { 6, 4 }, { 7, 4 }, 2668c2ecf20Sopenharmony_ci { 0 }, 2678c2ecf20Sopenharmony_ci}; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistatic const struct clk_div_table mcu_div_table[] = { 2708c2ecf20Sopenharmony_ci { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, 2718c2ecf20Sopenharmony_ci { 4, 16 }, { 5, 32 }, { 6, 64 }, { 7, 128 }, 2728c2ecf20Sopenharmony_ci { 8, 256 }, { 9, 512 }, { 10, 512}, { 11, 512 }, 2738c2ecf20Sopenharmony_ci { 12, 512 }, { 13, 512 }, { 14, 512}, { 15, 512 }, 2748c2ecf20Sopenharmony_ci { 0 }, 2758c2ecf20Sopenharmony_ci}; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_cistatic const struct clk_div_table apb_div_table[] = { 2788c2ecf20Sopenharmony_ci { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, 2798c2ecf20Sopenharmony_ci { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 }, 2808c2ecf20Sopenharmony_ci { 0 }, 2818c2ecf20Sopenharmony_ci}; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic const struct clk_div_table ck_trace_div_table[] = { 2848c2ecf20Sopenharmony_ci { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, 2858c2ecf20Sopenharmony_ci { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 }, 2868c2ecf20Sopenharmony_ci { 0 }, 2878c2ecf20Sopenharmony_ci}; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci#define MAX_MUX_CLK 2 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistruct stm32_mmux { 2928c2ecf20Sopenharmony_ci u8 nbr_clk; 2938c2ecf20Sopenharmony_ci struct clk_hw *hws[MAX_MUX_CLK]; 2948c2ecf20Sopenharmony_ci}; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistruct stm32_clk_mmux { 2978c2ecf20Sopenharmony_ci struct clk_mux mux; 2988c2ecf20Sopenharmony_ci struct stm32_mmux *mmux; 2998c2ecf20Sopenharmony_ci}; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistruct stm32_mgate { 3028c2ecf20Sopenharmony_ci u8 nbr_clk; 3038c2ecf20Sopenharmony_ci u32 flag; 3048c2ecf20Sopenharmony_ci}; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cistruct stm32_clk_mgate { 3078c2ecf20Sopenharmony_ci struct clk_gate gate; 3088c2ecf20Sopenharmony_ci struct stm32_mgate *mgate; 3098c2ecf20Sopenharmony_ci u32 mask; 3108c2ecf20Sopenharmony_ci}; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistruct clock_config { 3138c2ecf20Sopenharmony_ci u32 id; 3148c2ecf20Sopenharmony_ci const char *name; 3158c2ecf20Sopenharmony_ci const char *parent_name; 3168c2ecf20Sopenharmony_ci const char * const *parent_names; 3178c2ecf20Sopenharmony_ci int num_parents; 3188c2ecf20Sopenharmony_ci unsigned long flags; 3198c2ecf20Sopenharmony_ci void *cfg; 3208c2ecf20Sopenharmony_ci struct clk_hw * (*func)(struct device *dev, 3218c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 3228c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 3238c2ecf20Sopenharmony_ci const struct clock_config *cfg); 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci#define NO_ID ~0 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistruct gate_cfg { 3298c2ecf20Sopenharmony_ci u32 reg_off; 3308c2ecf20Sopenharmony_ci u8 bit_idx; 3318c2ecf20Sopenharmony_ci u8 gate_flags; 3328c2ecf20Sopenharmony_ci}; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_cistruct fixed_factor_cfg { 3358c2ecf20Sopenharmony_ci unsigned int mult; 3368c2ecf20Sopenharmony_ci unsigned int div; 3378c2ecf20Sopenharmony_ci}; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistruct div_cfg { 3408c2ecf20Sopenharmony_ci u32 reg_off; 3418c2ecf20Sopenharmony_ci u8 shift; 3428c2ecf20Sopenharmony_ci u8 width; 3438c2ecf20Sopenharmony_ci u8 div_flags; 3448c2ecf20Sopenharmony_ci const struct clk_div_table *table; 3458c2ecf20Sopenharmony_ci}; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistruct mux_cfg { 3488c2ecf20Sopenharmony_ci u32 reg_off; 3498c2ecf20Sopenharmony_ci u8 shift; 3508c2ecf20Sopenharmony_ci u8 width; 3518c2ecf20Sopenharmony_ci u8 mux_flags; 3528c2ecf20Sopenharmony_ci u32 *table; 3538c2ecf20Sopenharmony_ci}; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_cistruct stm32_gate_cfg { 3568c2ecf20Sopenharmony_ci struct gate_cfg *gate; 3578c2ecf20Sopenharmony_ci struct stm32_mgate *mgate; 3588c2ecf20Sopenharmony_ci const struct clk_ops *ops; 3598c2ecf20Sopenharmony_ci}; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistruct stm32_div_cfg { 3628c2ecf20Sopenharmony_ci struct div_cfg *div; 3638c2ecf20Sopenharmony_ci const struct clk_ops *ops; 3648c2ecf20Sopenharmony_ci}; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistruct stm32_mux_cfg { 3678c2ecf20Sopenharmony_ci struct mux_cfg *mux; 3688c2ecf20Sopenharmony_ci struct stm32_mmux *mmux; 3698c2ecf20Sopenharmony_ci const struct clk_ops *ops; 3708c2ecf20Sopenharmony_ci}; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci/* STM32 Composite clock */ 3738c2ecf20Sopenharmony_cistruct stm32_composite_cfg { 3748c2ecf20Sopenharmony_ci const struct stm32_gate_cfg *gate; 3758c2ecf20Sopenharmony_ci const struct stm32_div_cfg *div; 3768c2ecf20Sopenharmony_ci const struct stm32_mux_cfg *mux; 3778c2ecf20Sopenharmony_ci}; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic struct clk_hw * 3808c2ecf20Sopenharmony_ci_clk_hw_register_gate(struct device *dev, 3818c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 3828c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 3838c2ecf20Sopenharmony_ci const struct clock_config *cfg) 3848c2ecf20Sopenharmony_ci{ 3858c2ecf20Sopenharmony_ci struct gate_cfg *gate_cfg = cfg->cfg; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci return clk_hw_register_gate(dev, 3888c2ecf20Sopenharmony_ci cfg->name, 3898c2ecf20Sopenharmony_ci cfg->parent_name, 3908c2ecf20Sopenharmony_ci cfg->flags, 3918c2ecf20Sopenharmony_ci gate_cfg->reg_off + base, 3928c2ecf20Sopenharmony_ci gate_cfg->bit_idx, 3938c2ecf20Sopenharmony_ci gate_cfg->gate_flags, 3948c2ecf20Sopenharmony_ci lock); 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_cistatic struct clk_hw * 3988c2ecf20Sopenharmony_ci_clk_hw_register_fixed_factor(struct device *dev, 3998c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 4008c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 4018c2ecf20Sopenharmony_ci const struct clock_config *cfg) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci struct fixed_factor_cfg *ff_cfg = cfg->cfg; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci return clk_hw_register_fixed_factor(dev, cfg->name, cfg->parent_name, 4068c2ecf20Sopenharmony_ci cfg->flags, ff_cfg->mult, 4078c2ecf20Sopenharmony_ci ff_cfg->div); 4088c2ecf20Sopenharmony_ci} 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_cistatic struct clk_hw * 4118c2ecf20Sopenharmony_ci_clk_hw_register_divider_table(struct device *dev, 4128c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 4138c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 4148c2ecf20Sopenharmony_ci const struct clock_config *cfg) 4158c2ecf20Sopenharmony_ci{ 4168c2ecf20Sopenharmony_ci struct div_cfg *div_cfg = cfg->cfg; 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci return clk_hw_register_divider_table(dev, 4198c2ecf20Sopenharmony_ci cfg->name, 4208c2ecf20Sopenharmony_ci cfg->parent_name, 4218c2ecf20Sopenharmony_ci cfg->flags, 4228c2ecf20Sopenharmony_ci div_cfg->reg_off + base, 4238c2ecf20Sopenharmony_ci div_cfg->shift, 4248c2ecf20Sopenharmony_ci div_cfg->width, 4258c2ecf20Sopenharmony_ci div_cfg->div_flags, 4268c2ecf20Sopenharmony_ci div_cfg->table, 4278c2ecf20Sopenharmony_ci lock); 4288c2ecf20Sopenharmony_ci} 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_cistatic struct clk_hw * 4318c2ecf20Sopenharmony_ci_clk_hw_register_mux(struct device *dev, 4328c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 4338c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 4348c2ecf20Sopenharmony_ci const struct clock_config *cfg) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci struct mux_cfg *mux_cfg = cfg->cfg; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci return clk_hw_register_mux(dev, cfg->name, cfg->parent_names, 4398c2ecf20Sopenharmony_ci cfg->num_parents, cfg->flags, 4408c2ecf20Sopenharmony_ci mux_cfg->reg_off + base, mux_cfg->shift, 4418c2ecf20Sopenharmony_ci mux_cfg->width, mux_cfg->mux_flags, lock); 4428c2ecf20Sopenharmony_ci} 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci/* MP1 Gate clock with set & clear registers */ 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_cistatic int mp1_gate_clk_enable(struct clk_hw *hw) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci if (!clk_gate_ops.is_enabled(hw)) 4498c2ecf20Sopenharmony_ci clk_gate_ops.enable(hw); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci return 0; 4528c2ecf20Sopenharmony_ci} 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_cistatic void mp1_gate_clk_disable(struct clk_hw *hw) 4558c2ecf20Sopenharmony_ci{ 4568c2ecf20Sopenharmony_ci struct clk_gate *gate = to_clk_gate(hw); 4578c2ecf20Sopenharmony_ci unsigned long flags = 0; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci if (clk_gate_ops.is_enabled(hw)) { 4608c2ecf20Sopenharmony_ci spin_lock_irqsave(gate->lock, flags); 4618c2ecf20Sopenharmony_ci writel_relaxed(BIT(gate->bit_idx), gate->reg + RCC_CLR); 4628c2ecf20Sopenharmony_ci spin_unlock_irqrestore(gate->lock, flags); 4638c2ecf20Sopenharmony_ci } 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_cistatic const struct clk_ops mp1_gate_clk_ops = { 4678c2ecf20Sopenharmony_ci .enable = mp1_gate_clk_enable, 4688c2ecf20Sopenharmony_ci .disable = mp1_gate_clk_disable, 4698c2ecf20Sopenharmony_ci .is_enabled = clk_gate_is_enabled, 4708c2ecf20Sopenharmony_ci}; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_cistatic struct clk_hw *_get_stm32_mux(void __iomem *base, 4738c2ecf20Sopenharmony_ci const struct stm32_mux_cfg *cfg, 4748c2ecf20Sopenharmony_ci spinlock_t *lock) 4758c2ecf20Sopenharmony_ci{ 4768c2ecf20Sopenharmony_ci struct stm32_clk_mmux *mmux; 4778c2ecf20Sopenharmony_ci struct clk_mux *mux; 4788c2ecf20Sopenharmony_ci struct clk_hw *mux_hw; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci if (cfg->mmux) { 4818c2ecf20Sopenharmony_ci mmux = kzalloc(sizeof(*mmux), GFP_KERNEL); 4828c2ecf20Sopenharmony_ci if (!mmux) 4838c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci mmux->mux.reg = cfg->mux->reg_off + base; 4868c2ecf20Sopenharmony_ci mmux->mux.shift = cfg->mux->shift; 4878c2ecf20Sopenharmony_ci mmux->mux.mask = (1 << cfg->mux->width) - 1; 4888c2ecf20Sopenharmony_ci mmux->mux.flags = cfg->mux->mux_flags; 4898c2ecf20Sopenharmony_ci mmux->mux.table = cfg->mux->table; 4908c2ecf20Sopenharmony_ci mmux->mux.lock = lock; 4918c2ecf20Sopenharmony_ci mmux->mmux = cfg->mmux; 4928c2ecf20Sopenharmony_ci mux_hw = &mmux->mux.hw; 4938c2ecf20Sopenharmony_ci cfg->mmux->hws[cfg->mmux->nbr_clk++] = mux_hw; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci } else { 4968c2ecf20Sopenharmony_ci mux = kzalloc(sizeof(*mux), GFP_KERNEL); 4978c2ecf20Sopenharmony_ci if (!mux) 4988c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci mux->reg = cfg->mux->reg_off + base; 5018c2ecf20Sopenharmony_ci mux->shift = cfg->mux->shift; 5028c2ecf20Sopenharmony_ci mux->mask = (1 << cfg->mux->width) - 1; 5038c2ecf20Sopenharmony_ci mux->flags = cfg->mux->mux_flags; 5048c2ecf20Sopenharmony_ci mux->table = cfg->mux->table; 5058c2ecf20Sopenharmony_ci mux->lock = lock; 5068c2ecf20Sopenharmony_ci mux_hw = &mux->hw; 5078c2ecf20Sopenharmony_ci } 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci return mux_hw; 5108c2ecf20Sopenharmony_ci} 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_cistatic struct clk_hw *_get_stm32_div(void __iomem *base, 5138c2ecf20Sopenharmony_ci const struct stm32_div_cfg *cfg, 5148c2ecf20Sopenharmony_ci spinlock_t *lock) 5158c2ecf20Sopenharmony_ci{ 5168c2ecf20Sopenharmony_ci struct clk_divider *div; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci div = kzalloc(sizeof(*div), GFP_KERNEL); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci if (!div) 5218c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci div->reg = cfg->div->reg_off + base; 5248c2ecf20Sopenharmony_ci div->shift = cfg->div->shift; 5258c2ecf20Sopenharmony_ci div->width = cfg->div->width; 5268c2ecf20Sopenharmony_ci div->flags = cfg->div->div_flags; 5278c2ecf20Sopenharmony_ci div->table = cfg->div->table; 5288c2ecf20Sopenharmony_ci div->lock = lock; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci return &div->hw; 5318c2ecf20Sopenharmony_ci} 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_cistatic struct clk_hw * 5348c2ecf20Sopenharmony_ci_get_stm32_gate(void __iomem *base, 5358c2ecf20Sopenharmony_ci const struct stm32_gate_cfg *cfg, spinlock_t *lock) 5368c2ecf20Sopenharmony_ci{ 5378c2ecf20Sopenharmony_ci struct stm32_clk_mgate *mgate; 5388c2ecf20Sopenharmony_ci struct clk_gate *gate; 5398c2ecf20Sopenharmony_ci struct clk_hw *gate_hw; 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci if (cfg->mgate) { 5428c2ecf20Sopenharmony_ci mgate = kzalloc(sizeof(*mgate), GFP_KERNEL); 5438c2ecf20Sopenharmony_ci if (!mgate) 5448c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci mgate->gate.reg = cfg->gate->reg_off + base; 5478c2ecf20Sopenharmony_ci mgate->gate.bit_idx = cfg->gate->bit_idx; 5488c2ecf20Sopenharmony_ci mgate->gate.flags = cfg->gate->gate_flags; 5498c2ecf20Sopenharmony_ci mgate->gate.lock = lock; 5508c2ecf20Sopenharmony_ci mgate->mask = BIT(cfg->mgate->nbr_clk++); 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci mgate->mgate = cfg->mgate; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci gate_hw = &mgate->gate.hw; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci } else { 5578c2ecf20Sopenharmony_ci gate = kzalloc(sizeof(*gate), GFP_KERNEL); 5588c2ecf20Sopenharmony_ci if (!gate) 5598c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci gate->reg = cfg->gate->reg_off + base; 5628c2ecf20Sopenharmony_ci gate->bit_idx = cfg->gate->bit_idx; 5638c2ecf20Sopenharmony_ci gate->flags = cfg->gate->gate_flags; 5648c2ecf20Sopenharmony_ci gate->lock = lock; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci gate_hw = &gate->hw; 5678c2ecf20Sopenharmony_ci } 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci return gate_hw; 5708c2ecf20Sopenharmony_ci} 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_cistatic struct clk_hw * 5738c2ecf20Sopenharmony_ciclk_stm32_register_gate_ops(struct device *dev, 5748c2ecf20Sopenharmony_ci const char *name, 5758c2ecf20Sopenharmony_ci const char *parent_name, 5768c2ecf20Sopenharmony_ci unsigned long flags, 5778c2ecf20Sopenharmony_ci void __iomem *base, 5788c2ecf20Sopenharmony_ci const struct stm32_gate_cfg *cfg, 5798c2ecf20Sopenharmony_ci spinlock_t *lock) 5808c2ecf20Sopenharmony_ci{ 5818c2ecf20Sopenharmony_ci struct clk_init_data init = { NULL }; 5828c2ecf20Sopenharmony_ci struct clk_hw *hw; 5838c2ecf20Sopenharmony_ci int ret; 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci init.name = name; 5868c2ecf20Sopenharmony_ci init.parent_names = &parent_name; 5878c2ecf20Sopenharmony_ci init.num_parents = 1; 5888c2ecf20Sopenharmony_ci init.flags = flags; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci init.ops = &clk_gate_ops; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci if (cfg->ops) 5938c2ecf20Sopenharmony_ci init.ops = cfg->ops; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci hw = _get_stm32_gate(base, cfg, lock); 5968c2ecf20Sopenharmony_ci if (IS_ERR(hw)) 5978c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci hw->init = &init; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci ret = clk_hw_register(dev, hw); 6028c2ecf20Sopenharmony_ci if (ret) 6038c2ecf20Sopenharmony_ci hw = ERR_PTR(ret); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci return hw; 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_cistatic struct clk_hw * 6098c2ecf20Sopenharmony_ciclk_stm32_register_composite(struct device *dev, 6108c2ecf20Sopenharmony_ci const char *name, const char * const *parent_names, 6118c2ecf20Sopenharmony_ci int num_parents, void __iomem *base, 6128c2ecf20Sopenharmony_ci const struct stm32_composite_cfg *cfg, 6138c2ecf20Sopenharmony_ci unsigned long flags, spinlock_t *lock) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci const struct clk_ops *mux_ops, *div_ops, *gate_ops; 6168c2ecf20Sopenharmony_ci struct clk_hw *mux_hw, *div_hw, *gate_hw; 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci mux_hw = NULL; 6198c2ecf20Sopenharmony_ci div_hw = NULL; 6208c2ecf20Sopenharmony_ci gate_hw = NULL; 6218c2ecf20Sopenharmony_ci mux_ops = NULL; 6228c2ecf20Sopenharmony_ci div_ops = NULL; 6238c2ecf20Sopenharmony_ci gate_ops = NULL; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci if (cfg->mux) { 6268c2ecf20Sopenharmony_ci mux_hw = _get_stm32_mux(base, cfg->mux, lock); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci if (!IS_ERR(mux_hw)) { 6298c2ecf20Sopenharmony_ci mux_ops = &clk_mux_ops; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci if (cfg->mux->ops) 6328c2ecf20Sopenharmony_ci mux_ops = cfg->mux->ops; 6338c2ecf20Sopenharmony_ci } 6348c2ecf20Sopenharmony_ci } 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci if (cfg->div) { 6378c2ecf20Sopenharmony_ci div_hw = _get_stm32_div(base, cfg->div, lock); 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci if (!IS_ERR(div_hw)) { 6408c2ecf20Sopenharmony_ci div_ops = &clk_divider_ops; 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci if (cfg->div->ops) 6438c2ecf20Sopenharmony_ci div_ops = cfg->div->ops; 6448c2ecf20Sopenharmony_ci } 6458c2ecf20Sopenharmony_ci } 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci if (cfg->gate) { 6488c2ecf20Sopenharmony_ci gate_hw = _get_stm32_gate(base, cfg->gate, lock); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci if (!IS_ERR(gate_hw)) { 6518c2ecf20Sopenharmony_ci gate_ops = &clk_gate_ops; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci if (cfg->gate->ops) 6548c2ecf20Sopenharmony_ci gate_ops = cfg->gate->ops; 6558c2ecf20Sopenharmony_ci } 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci return clk_hw_register_composite(dev, name, parent_names, num_parents, 6598c2ecf20Sopenharmony_ci mux_hw, mux_ops, div_hw, div_ops, 6608c2ecf20Sopenharmony_ci gate_hw, gate_ops, flags); 6618c2ecf20Sopenharmony_ci} 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci#define to_clk_mgate(_gate) container_of(_gate, struct stm32_clk_mgate, gate) 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_cistatic int mp1_mgate_clk_enable(struct clk_hw *hw) 6668c2ecf20Sopenharmony_ci{ 6678c2ecf20Sopenharmony_ci struct clk_gate *gate = to_clk_gate(hw); 6688c2ecf20Sopenharmony_ci struct stm32_clk_mgate *clk_mgate = to_clk_mgate(gate); 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci clk_mgate->mgate->flag |= clk_mgate->mask; 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci mp1_gate_clk_enable(hw); 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci return 0; 6758c2ecf20Sopenharmony_ci} 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_cistatic void mp1_mgate_clk_disable(struct clk_hw *hw) 6788c2ecf20Sopenharmony_ci{ 6798c2ecf20Sopenharmony_ci struct clk_gate *gate = to_clk_gate(hw); 6808c2ecf20Sopenharmony_ci struct stm32_clk_mgate *clk_mgate = to_clk_mgate(gate); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci clk_mgate->mgate->flag &= ~clk_mgate->mask; 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci if (clk_mgate->mgate->flag == 0) 6858c2ecf20Sopenharmony_ci mp1_gate_clk_disable(hw); 6868c2ecf20Sopenharmony_ci} 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_cistatic const struct clk_ops mp1_mgate_clk_ops = { 6898c2ecf20Sopenharmony_ci .enable = mp1_mgate_clk_enable, 6908c2ecf20Sopenharmony_ci .disable = mp1_mgate_clk_disable, 6918c2ecf20Sopenharmony_ci .is_enabled = clk_gate_is_enabled, 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci}; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci#define to_clk_mmux(_mux) container_of(_mux, struct stm32_clk_mmux, mux) 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_cistatic u8 clk_mmux_get_parent(struct clk_hw *hw) 6988c2ecf20Sopenharmony_ci{ 6998c2ecf20Sopenharmony_ci return clk_mux_ops.get_parent(hw); 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_cistatic int clk_mmux_set_parent(struct clk_hw *hw, u8 index) 7038c2ecf20Sopenharmony_ci{ 7048c2ecf20Sopenharmony_ci struct clk_mux *mux = to_clk_mux(hw); 7058c2ecf20Sopenharmony_ci struct stm32_clk_mmux *clk_mmux = to_clk_mmux(mux); 7068c2ecf20Sopenharmony_ci struct clk_hw *hwp; 7078c2ecf20Sopenharmony_ci int ret, n; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci ret = clk_mux_ops.set_parent(hw, index); 7108c2ecf20Sopenharmony_ci if (ret) 7118c2ecf20Sopenharmony_ci return ret; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci hwp = clk_hw_get_parent(hw); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci for (n = 0; n < clk_mmux->mmux->nbr_clk; n++) 7168c2ecf20Sopenharmony_ci if (clk_mmux->mmux->hws[n] != hw) 7178c2ecf20Sopenharmony_ci clk_hw_reparent(clk_mmux->mmux->hws[n], hwp); 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci return 0; 7208c2ecf20Sopenharmony_ci} 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_cistatic const struct clk_ops clk_mmux_ops = { 7238c2ecf20Sopenharmony_ci .get_parent = clk_mmux_get_parent, 7248c2ecf20Sopenharmony_ci .set_parent = clk_mmux_set_parent, 7258c2ecf20Sopenharmony_ci .determine_rate = __clk_mux_determine_rate, 7268c2ecf20Sopenharmony_ci}; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci/* STM32 PLL */ 7298c2ecf20Sopenharmony_cistruct stm32_pll_obj { 7308c2ecf20Sopenharmony_ci /* lock pll enable/disable registers */ 7318c2ecf20Sopenharmony_ci spinlock_t *lock; 7328c2ecf20Sopenharmony_ci void __iomem *reg; 7338c2ecf20Sopenharmony_ci struct clk_hw hw; 7348c2ecf20Sopenharmony_ci}; 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci#define to_pll(_hw) container_of(_hw, struct stm32_pll_obj, hw) 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci#define PLL_ON BIT(0) 7398c2ecf20Sopenharmony_ci#define PLL_RDY BIT(1) 7408c2ecf20Sopenharmony_ci#define DIVN_MASK 0x1FF 7418c2ecf20Sopenharmony_ci#define DIVM_MASK 0x3F 7428c2ecf20Sopenharmony_ci#define DIVM_SHIFT 16 7438c2ecf20Sopenharmony_ci#define DIVN_SHIFT 0 7448c2ecf20Sopenharmony_ci#define FRAC_OFFSET 0xC 7458c2ecf20Sopenharmony_ci#define FRAC_MASK 0x1FFF 7468c2ecf20Sopenharmony_ci#define FRAC_SHIFT 3 7478c2ecf20Sopenharmony_ci#define FRACLE BIT(16) 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_cistatic int __pll_is_enabled(struct clk_hw *hw) 7508c2ecf20Sopenharmony_ci{ 7518c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci return readl_relaxed(clk_elem->reg) & PLL_ON; 7548c2ecf20Sopenharmony_ci} 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci#define TIMEOUT 5 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_cistatic int pll_enable(struct clk_hw *hw) 7598c2ecf20Sopenharmony_ci{ 7608c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 7618c2ecf20Sopenharmony_ci u32 reg; 7628c2ecf20Sopenharmony_ci unsigned long flags = 0; 7638c2ecf20Sopenharmony_ci unsigned int timeout = TIMEOUT; 7648c2ecf20Sopenharmony_ci int bit_status = 0; 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci spin_lock_irqsave(clk_elem->lock, flags); 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci if (__pll_is_enabled(hw)) 7698c2ecf20Sopenharmony_ci goto unlock; 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci reg = readl_relaxed(clk_elem->reg); 7728c2ecf20Sopenharmony_ci reg |= PLL_ON; 7738c2ecf20Sopenharmony_ci writel_relaxed(reg, clk_elem->reg); 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci /* We can't use readl_poll_timeout() because we can be blocked if 7768c2ecf20Sopenharmony_ci * someone enables this clock before clocksource changes. 7778c2ecf20Sopenharmony_ci * Only jiffies counter is available. Jiffies are incremented by 7788c2ecf20Sopenharmony_ci * interruptions and enable op does not allow to be interrupted. 7798c2ecf20Sopenharmony_ci */ 7808c2ecf20Sopenharmony_ci do { 7818c2ecf20Sopenharmony_ci bit_status = !(readl_relaxed(clk_elem->reg) & PLL_RDY); 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci if (bit_status) 7848c2ecf20Sopenharmony_ci udelay(120); 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci } while (bit_status && --timeout); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ciunlock: 7898c2ecf20Sopenharmony_ci spin_unlock_irqrestore(clk_elem->lock, flags); 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci return bit_status; 7928c2ecf20Sopenharmony_ci} 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_cistatic void pll_disable(struct clk_hw *hw) 7958c2ecf20Sopenharmony_ci{ 7968c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 7978c2ecf20Sopenharmony_ci u32 reg; 7988c2ecf20Sopenharmony_ci unsigned long flags = 0; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci spin_lock_irqsave(clk_elem->lock, flags); 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci reg = readl_relaxed(clk_elem->reg); 8038c2ecf20Sopenharmony_ci reg &= ~PLL_ON; 8048c2ecf20Sopenharmony_ci writel_relaxed(reg, clk_elem->reg); 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci spin_unlock_irqrestore(clk_elem->lock, flags); 8078c2ecf20Sopenharmony_ci} 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_cistatic u32 pll_frac_val(struct clk_hw *hw) 8108c2ecf20Sopenharmony_ci{ 8118c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 8128c2ecf20Sopenharmony_ci u32 reg, frac = 0; 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci reg = readl_relaxed(clk_elem->reg + FRAC_OFFSET); 8158c2ecf20Sopenharmony_ci if (reg & FRACLE) 8168c2ecf20Sopenharmony_ci frac = (reg >> FRAC_SHIFT) & FRAC_MASK; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci return frac; 8198c2ecf20Sopenharmony_ci} 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_cistatic unsigned long pll_recalc_rate(struct clk_hw *hw, 8228c2ecf20Sopenharmony_ci unsigned long parent_rate) 8238c2ecf20Sopenharmony_ci{ 8248c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 8258c2ecf20Sopenharmony_ci u32 reg; 8268c2ecf20Sopenharmony_ci u32 frac, divm, divn; 8278c2ecf20Sopenharmony_ci u64 rate, rate_frac = 0; 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci reg = readl_relaxed(clk_elem->reg + 4); 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci divm = ((reg >> DIVM_SHIFT) & DIVM_MASK) + 1; 8328c2ecf20Sopenharmony_ci divn = ((reg >> DIVN_SHIFT) & DIVN_MASK) + 1; 8338c2ecf20Sopenharmony_ci rate = (u64)parent_rate * divn; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci do_div(rate, divm); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci frac = pll_frac_val(hw); 8388c2ecf20Sopenharmony_ci if (frac) { 8398c2ecf20Sopenharmony_ci rate_frac = (u64)parent_rate * (u64)frac; 8408c2ecf20Sopenharmony_ci do_div(rate_frac, (divm * 8192)); 8418c2ecf20Sopenharmony_ci } 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci return rate + rate_frac; 8448c2ecf20Sopenharmony_ci} 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic int pll_is_enabled(struct clk_hw *hw) 8478c2ecf20Sopenharmony_ci{ 8488c2ecf20Sopenharmony_ci struct stm32_pll_obj *clk_elem = to_pll(hw); 8498c2ecf20Sopenharmony_ci unsigned long flags = 0; 8508c2ecf20Sopenharmony_ci int ret; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci spin_lock_irqsave(clk_elem->lock, flags); 8538c2ecf20Sopenharmony_ci ret = __pll_is_enabled(hw); 8548c2ecf20Sopenharmony_ci spin_unlock_irqrestore(clk_elem->lock, flags); 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci return ret; 8578c2ecf20Sopenharmony_ci} 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_cistatic const struct clk_ops pll_ops = { 8608c2ecf20Sopenharmony_ci .enable = pll_enable, 8618c2ecf20Sopenharmony_ci .disable = pll_disable, 8628c2ecf20Sopenharmony_ci .recalc_rate = pll_recalc_rate, 8638c2ecf20Sopenharmony_ci .is_enabled = pll_is_enabled, 8648c2ecf20Sopenharmony_ci}; 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_cistatic struct clk_hw *clk_register_pll(struct device *dev, const char *name, 8678c2ecf20Sopenharmony_ci const char *parent_name, 8688c2ecf20Sopenharmony_ci void __iomem *reg, 8698c2ecf20Sopenharmony_ci unsigned long flags, 8708c2ecf20Sopenharmony_ci spinlock_t *lock) 8718c2ecf20Sopenharmony_ci{ 8728c2ecf20Sopenharmony_ci struct stm32_pll_obj *element; 8738c2ecf20Sopenharmony_ci struct clk_init_data init; 8748c2ecf20Sopenharmony_ci struct clk_hw *hw; 8758c2ecf20Sopenharmony_ci int err; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci element = kzalloc(sizeof(*element), GFP_KERNEL); 8788c2ecf20Sopenharmony_ci if (!element) 8798c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci init.name = name; 8828c2ecf20Sopenharmony_ci init.ops = &pll_ops; 8838c2ecf20Sopenharmony_ci init.flags = flags; 8848c2ecf20Sopenharmony_ci init.parent_names = &parent_name; 8858c2ecf20Sopenharmony_ci init.num_parents = 1; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci element->hw.init = &init; 8888c2ecf20Sopenharmony_ci element->reg = reg; 8898c2ecf20Sopenharmony_ci element->lock = lock; 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci hw = &element->hw; 8928c2ecf20Sopenharmony_ci err = clk_hw_register(dev, hw); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci if (err) { 8958c2ecf20Sopenharmony_ci kfree(element); 8968c2ecf20Sopenharmony_ci return ERR_PTR(err); 8978c2ecf20Sopenharmony_ci } 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci return hw; 9008c2ecf20Sopenharmony_ci} 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci/* Kernel Timer */ 9038c2ecf20Sopenharmony_cistruct timer_cker { 9048c2ecf20Sopenharmony_ci /* lock the kernel output divider register */ 9058c2ecf20Sopenharmony_ci spinlock_t *lock; 9068c2ecf20Sopenharmony_ci void __iomem *apbdiv; 9078c2ecf20Sopenharmony_ci void __iomem *timpre; 9088c2ecf20Sopenharmony_ci struct clk_hw hw; 9098c2ecf20Sopenharmony_ci}; 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci#define to_timer_cker(_hw) container_of(_hw, struct timer_cker, hw) 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci#define APB_DIV_MASK 0x07 9148c2ecf20Sopenharmony_ci#define TIM_PRE_MASK 0x01 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_cistatic unsigned long __bestmult(struct clk_hw *hw, unsigned long rate, 9178c2ecf20Sopenharmony_ci unsigned long parent_rate) 9188c2ecf20Sopenharmony_ci{ 9198c2ecf20Sopenharmony_ci struct timer_cker *tim_ker = to_timer_cker(hw); 9208c2ecf20Sopenharmony_ci u32 prescaler; 9218c2ecf20Sopenharmony_ci unsigned int mult = 0; 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci prescaler = readl_relaxed(tim_ker->apbdiv) & APB_DIV_MASK; 9248c2ecf20Sopenharmony_ci if (prescaler < 2) 9258c2ecf20Sopenharmony_ci return 1; 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci mult = 2; 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci if (rate / parent_rate >= 4) 9308c2ecf20Sopenharmony_ci mult = 4; 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci return mult; 9338c2ecf20Sopenharmony_ci} 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_cistatic long timer_ker_round_rate(struct clk_hw *hw, unsigned long rate, 9368c2ecf20Sopenharmony_ci unsigned long *parent_rate) 9378c2ecf20Sopenharmony_ci{ 9388c2ecf20Sopenharmony_ci unsigned long factor = __bestmult(hw, rate, *parent_rate); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci return *parent_rate * factor; 9418c2ecf20Sopenharmony_ci} 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_cistatic int timer_ker_set_rate(struct clk_hw *hw, unsigned long rate, 9448c2ecf20Sopenharmony_ci unsigned long parent_rate) 9458c2ecf20Sopenharmony_ci{ 9468c2ecf20Sopenharmony_ci struct timer_cker *tim_ker = to_timer_cker(hw); 9478c2ecf20Sopenharmony_ci unsigned long flags = 0; 9488c2ecf20Sopenharmony_ci unsigned long factor = __bestmult(hw, rate, parent_rate); 9498c2ecf20Sopenharmony_ci int ret = 0; 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci spin_lock_irqsave(tim_ker->lock, flags); 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci switch (factor) { 9548c2ecf20Sopenharmony_ci case 1: 9558c2ecf20Sopenharmony_ci break; 9568c2ecf20Sopenharmony_ci case 2: 9578c2ecf20Sopenharmony_ci writel_relaxed(0, tim_ker->timpre); 9588c2ecf20Sopenharmony_ci break; 9598c2ecf20Sopenharmony_ci case 4: 9608c2ecf20Sopenharmony_ci writel_relaxed(1, tim_ker->timpre); 9618c2ecf20Sopenharmony_ci break; 9628c2ecf20Sopenharmony_ci default: 9638c2ecf20Sopenharmony_ci ret = -EINVAL; 9648c2ecf20Sopenharmony_ci } 9658c2ecf20Sopenharmony_ci spin_unlock_irqrestore(tim_ker->lock, flags); 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci return ret; 9688c2ecf20Sopenharmony_ci} 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_cistatic unsigned long timer_ker_recalc_rate(struct clk_hw *hw, 9718c2ecf20Sopenharmony_ci unsigned long parent_rate) 9728c2ecf20Sopenharmony_ci{ 9738c2ecf20Sopenharmony_ci struct timer_cker *tim_ker = to_timer_cker(hw); 9748c2ecf20Sopenharmony_ci u32 prescaler, timpre; 9758c2ecf20Sopenharmony_ci u32 mul; 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci prescaler = readl_relaxed(tim_ker->apbdiv) & APB_DIV_MASK; 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci timpre = readl_relaxed(tim_ker->timpre) & TIM_PRE_MASK; 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci if (!prescaler) 9828c2ecf20Sopenharmony_ci return parent_rate; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci mul = (timpre + 1) * 2; 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci return parent_rate * mul; 9878c2ecf20Sopenharmony_ci} 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_cistatic const struct clk_ops timer_ker_ops = { 9908c2ecf20Sopenharmony_ci .recalc_rate = timer_ker_recalc_rate, 9918c2ecf20Sopenharmony_ci .round_rate = timer_ker_round_rate, 9928c2ecf20Sopenharmony_ci .set_rate = timer_ker_set_rate, 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci}; 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_cistatic struct clk_hw *clk_register_cktim(struct device *dev, const char *name, 9978c2ecf20Sopenharmony_ci const char *parent_name, 9988c2ecf20Sopenharmony_ci unsigned long flags, 9998c2ecf20Sopenharmony_ci void __iomem *apbdiv, 10008c2ecf20Sopenharmony_ci void __iomem *timpre, 10018c2ecf20Sopenharmony_ci spinlock_t *lock) 10028c2ecf20Sopenharmony_ci{ 10038c2ecf20Sopenharmony_ci struct timer_cker *tim_ker; 10048c2ecf20Sopenharmony_ci struct clk_init_data init; 10058c2ecf20Sopenharmony_ci struct clk_hw *hw; 10068c2ecf20Sopenharmony_ci int err; 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci tim_ker = kzalloc(sizeof(*tim_ker), GFP_KERNEL); 10098c2ecf20Sopenharmony_ci if (!tim_ker) 10108c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci init.name = name; 10138c2ecf20Sopenharmony_ci init.ops = &timer_ker_ops; 10148c2ecf20Sopenharmony_ci init.flags = flags; 10158c2ecf20Sopenharmony_ci init.parent_names = &parent_name; 10168c2ecf20Sopenharmony_ci init.num_parents = 1; 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_ci tim_ker->hw.init = &init; 10198c2ecf20Sopenharmony_ci tim_ker->lock = lock; 10208c2ecf20Sopenharmony_ci tim_ker->apbdiv = apbdiv; 10218c2ecf20Sopenharmony_ci tim_ker->timpre = timpre; 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci hw = &tim_ker->hw; 10248c2ecf20Sopenharmony_ci err = clk_hw_register(dev, hw); 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci if (err) { 10278c2ecf20Sopenharmony_ci kfree(tim_ker); 10288c2ecf20Sopenharmony_ci return ERR_PTR(err); 10298c2ecf20Sopenharmony_ci } 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci return hw; 10328c2ecf20Sopenharmony_ci} 10338c2ecf20Sopenharmony_ci 10348c2ecf20Sopenharmony_cistruct stm32_pll_cfg { 10358c2ecf20Sopenharmony_ci u32 offset; 10368c2ecf20Sopenharmony_ci}; 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_cistatic struct clk_hw *_clk_register_pll(struct device *dev, 10398c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 10408c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 10418c2ecf20Sopenharmony_ci const struct clock_config *cfg) 10428c2ecf20Sopenharmony_ci{ 10438c2ecf20Sopenharmony_ci struct stm32_pll_cfg *stm_pll_cfg = cfg->cfg; 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci return clk_register_pll(dev, cfg->name, cfg->parent_name, 10468c2ecf20Sopenharmony_ci base + stm_pll_cfg->offset, cfg->flags, lock); 10478c2ecf20Sopenharmony_ci} 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_cistruct stm32_cktim_cfg { 10508c2ecf20Sopenharmony_ci u32 offset_apbdiv; 10518c2ecf20Sopenharmony_ci u32 offset_timpre; 10528c2ecf20Sopenharmony_ci}; 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_cistatic struct clk_hw *_clk_register_cktim(struct device *dev, 10558c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 10568c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 10578c2ecf20Sopenharmony_ci const struct clock_config *cfg) 10588c2ecf20Sopenharmony_ci{ 10598c2ecf20Sopenharmony_ci struct stm32_cktim_cfg *cktim_cfg = cfg->cfg; 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci return clk_register_cktim(dev, cfg->name, cfg->parent_name, cfg->flags, 10628c2ecf20Sopenharmony_ci cktim_cfg->offset_apbdiv + base, 10638c2ecf20Sopenharmony_ci cktim_cfg->offset_timpre + base, lock); 10648c2ecf20Sopenharmony_ci} 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_cistatic struct clk_hw * 10678c2ecf20Sopenharmony_ci_clk_stm32_register_gate(struct device *dev, 10688c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 10698c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 10708c2ecf20Sopenharmony_ci const struct clock_config *cfg) 10718c2ecf20Sopenharmony_ci{ 10728c2ecf20Sopenharmony_ci return clk_stm32_register_gate_ops(dev, 10738c2ecf20Sopenharmony_ci cfg->name, 10748c2ecf20Sopenharmony_ci cfg->parent_name, 10758c2ecf20Sopenharmony_ci cfg->flags, 10768c2ecf20Sopenharmony_ci base, 10778c2ecf20Sopenharmony_ci cfg->cfg, 10788c2ecf20Sopenharmony_ci lock); 10798c2ecf20Sopenharmony_ci} 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_cistatic struct clk_hw * 10828c2ecf20Sopenharmony_ci_clk_stm32_register_composite(struct device *dev, 10838c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 10848c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 10858c2ecf20Sopenharmony_ci const struct clock_config *cfg) 10868c2ecf20Sopenharmony_ci{ 10878c2ecf20Sopenharmony_ci return clk_stm32_register_composite(dev, cfg->name, cfg->parent_names, 10888c2ecf20Sopenharmony_ci cfg->num_parents, base, cfg->cfg, 10898c2ecf20Sopenharmony_ci cfg->flags, lock); 10908c2ecf20Sopenharmony_ci} 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci#define GATE(_id, _name, _parent, _flags, _offset, _bit_idx, _gate_flags)\ 10938c2ecf20Sopenharmony_ci{\ 10948c2ecf20Sopenharmony_ci .id = _id,\ 10958c2ecf20Sopenharmony_ci .name = _name,\ 10968c2ecf20Sopenharmony_ci .parent_name = _parent,\ 10978c2ecf20Sopenharmony_ci .flags = _flags,\ 10988c2ecf20Sopenharmony_ci .cfg = &(struct gate_cfg) {\ 10998c2ecf20Sopenharmony_ci .reg_off = _offset,\ 11008c2ecf20Sopenharmony_ci .bit_idx = _bit_idx,\ 11018c2ecf20Sopenharmony_ci .gate_flags = _gate_flags,\ 11028c2ecf20Sopenharmony_ci },\ 11038c2ecf20Sopenharmony_ci .func = _clk_hw_register_gate,\ 11048c2ecf20Sopenharmony_ci} 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_ci#define FIXED_FACTOR(_id, _name, _parent, _flags, _mult, _div)\ 11078c2ecf20Sopenharmony_ci{\ 11088c2ecf20Sopenharmony_ci .id = _id,\ 11098c2ecf20Sopenharmony_ci .name = _name,\ 11108c2ecf20Sopenharmony_ci .parent_name = _parent,\ 11118c2ecf20Sopenharmony_ci .flags = _flags,\ 11128c2ecf20Sopenharmony_ci .cfg = &(struct fixed_factor_cfg) {\ 11138c2ecf20Sopenharmony_ci .mult = _mult,\ 11148c2ecf20Sopenharmony_ci .div = _div,\ 11158c2ecf20Sopenharmony_ci },\ 11168c2ecf20Sopenharmony_ci .func = _clk_hw_register_fixed_factor,\ 11178c2ecf20Sopenharmony_ci} 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci#define DIV_TABLE(_id, _name, _parent, _flags, _offset, _shift, _width,\ 11208c2ecf20Sopenharmony_ci _div_flags, _div_table)\ 11218c2ecf20Sopenharmony_ci{\ 11228c2ecf20Sopenharmony_ci .id = _id,\ 11238c2ecf20Sopenharmony_ci .name = _name,\ 11248c2ecf20Sopenharmony_ci .parent_name = _parent,\ 11258c2ecf20Sopenharmony_ci .flags = _flags,\ 11268c2ecf20Sopenharmony_ci .cfg = &(struct div_cfg) {\ 11278c2ecf20Sopenharmony_ci .reg_off = _offset,\ 11288c2ecf20Sopenharmony_ci .shift = _shift,\ 11298c2ecf20Sopenharmony_ci .width = _width,\ 11308c2ecf20Sopenharmony_ci .div_flags = _div_flags,\ 11318c2ecf20Sopenharmony_ci .table = _div_table,\ 11328c2ecf20Sopenharmony_ci },\ 11338c2ecf20Sopenharmony_ci .func = _clk_hw_register_divider_table,\ 11348c2ecf20Sopenharmony_ci} 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci#define DIV(_id, _name, _parent, _flags, _offset, _shift, _width, _div_flags)\ 11378c2ecf20Sopenharmony_ci DIV_TABLE(_id, _name, _parent, _flags, _offset, _shift, _width,\ 11388c2ecf20Sopenharmony_ci _div_flags, NULL) 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci#define MUX(_id, _name, _parents, _flags, _offset, _shift, _width, _mux_flags)\ 11418c2ecf20Sopenharmony_ci{\ 11428c2ecf20Sopenharmony_ci .id = _id,\ 11438c2ecf20Sopenharmony_ci .name = _name,\ 11448c2ecf20Sopenharmony_ci .parent_names = _parents,\ 11458c2ecf20Sopenharmony_ci .num_parents = ARRAY_SIZE(_parents),\ 11468c2ecf20Sopenharmony_ci .flags = _flags,\ 11478c2ecf20Sopenharmony_ci .cfg = &(struct mux_cfg) {\ 11488c2ecf20Sopenharmony_ci .reg_off = _offset,\ 11498c2ecf20Sopenharmony_ci .shift = _shift,\ 11508c2ecf20Sopenharmony_ci .width = _width,\ 11518c2ecf20Sopenharmony_ci .mux_flags = _mux_flags,\ 11528c2ecf20Sopenharmony_ci },\ 11538c2ecf20Sopenharmony_ci .func = _clk_hw_register_mux,\ 11548c2ecf20Sopenharmony_ci} 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci#define PLL(_id, _name, _parent, _flags, _offset)\ 11578c2ecf20Sopenharmony_ci{\ 11588c2ecf20Sopenharmony_ci .id = _id,\ 11598c2ecf20Sopenharmony_ci .name = _name,\ 11608c2ecf20Sopenharmony_ci .parent_name = _parent,\ 11618c2ecf20Sopenharmony_ci .flags = _flags,\ 11628c2ecf20Sopenharmony_ci .cfg = &(struct stm32_pll_cfg) {\ 11638c2ecf20Sopenharmony_ci .offset = _offset,\ 11648c2ecf20Sopenharmony_ci },\ 11658c2ecf20Sopenharmony_ci .func = _clk_register_pll,\ 11668c2ecf20Sopenharmony_ci} 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci#define STM32_CKTIM(_name, _parent, _flags, _offset_apbdiv, _offset_timpre)\ 11698c2ecf20Sopenharmony_ci{\ 11708c2ecf20Sopenharmony_ci .id = NO_ID,\ 11718c2ecf20Sopenharmony_ci .name = _name,\ 11728c2ecf20Sopenharmony_ci .parent_name = _parent,\ 11738c2ecf20Sopenharmony_ci .flags = _flags,\ 11748c2ecf20Sopenharmony_ci .cfg = &(struct stm32_cktim_cfg) {\ 11758c2ecf20Sopenharmony_ci .offset_apbdiv = _offset_apbdiv,\ 11768c2ecf20Sopenharmony_ci .offset_timpre = _offset_timpre,\ 11778c2ecf20Sopenharmony_ci },\ 11788c2ecf20Sopenharmony_ci .func = _clk_register_cktim,\ 11798c2ecf20Sopenharmony_ci} 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci#define STM32_TIM(_id, _name, _parent, _offset_set, _bit_idx)\ 11828c2ecf20Sopenharmony_ci GATE_MP1(_id, _name, _parent, CLK_SET_RATE_PARENT,\ 11838c2ecf20Sopenharmony_ci _offset_set, _bit_idx, 0) 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci/* STM32 GATE */ 11868c2ecf20Sopenharmony_ci#define STM32_GATE(_id, _name, _parent, _flags, _gate)\ 11878c2ecf20Sopenharmony_ci{\ 11888c2ecf20Sopenharmony_ci .id = _id,\ 11898c2ecf20Sopenharmony_ci .name = _name,\ 11908c2ecf20Sopenharmony_ci .parent_name = _parent,\ 11918c2ecf20Sopenharmony_ci .flags = _flags,\ 11928c2ecf20Sopenharmony_ci .cfg = (struct stm32_gate_cfg *) {_gate},\ 11938c2ecf20Sopenharmony_ci .func = _clk_stm32_register_gate,\ 11948c2ecf20Sopenharmony_ci} 11958c2ecf20Sopenharmony_ci 11968c2ecf20Sopenharmony_ci#define _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags, _mgate, _ops)\ 11978c2ecf20Sopenharmony_ci (&(struct stm32_gate_cfg) {\ 11988c2ecf20Sopenharmony_ci &(struct gate_cfg) {\ 11998c2ecf20Sopenharmony_ci .reg_off = _gate_offset,\ 12008c2ecf20Sopenharmony_ci .bit_idx = _gate_bit_idx,\ 12018c2ecf20Sopenharmony_ci .gate_flags = _gate_flags,\ 12028c2ecf20Sopenharmony_ci },\ 12038c2ecf20Sopenharmony_ci .mgate = _mgate,\ 12048c2ecf20Sopenharmony_ci .ops = _ops,\ 12058c2ecf20Sopenharmony_ci }) 12068c2ecf20Sopenharmony_ci 12078c2ecf20Sopenharmony_ci#define _STM32_MGATE(_mgate)\ 12088c2ecf20Sopenharmony_ci (&per_gate_cfg[_mgate]) 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_ci#define _GATE(_gate_offset, _gate_bit_idx, _gate_flags)\ 12118c2ecf20Sopenharmony_ci _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags,\ 12128c2ecf20Sopenharmony_ci NULL, NULL)\ 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_ci#define _GATE_MP1(_gate_offset, _gate_bit_idx, _gate_flags)\ 12158c2ecf20Sopenharmony_ci _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags,\ 12168c2ecf20Sopenharmony_ci NULL, &mp1_gate_clk_ops)\ 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci#define _MGATE_MP1(_mgate)\ 12198c2ecf20Sopenharmony_ci .gate = &per_gate_cfg[_mgate] 12208c2ecf20Sopenharmony_ci 12218c2ecf20Sopenharmony_ci#define GATE_MP1(_id, _name, _parent, _flags, _offset, _bit_idx, _gate_flags)\ 12228c2ecf20Sopenharmony_ci STM32_GATE(_id, _name, _parent, _flags,\ 12238c2ecf20Sopenharmony_ci _GATE_MP1(_offset, _bit_idx, _gate_flags)) 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci#define MGATE_MP1(_id, _name, _parent, _flags, _mgate)\ 12268c2ecf20Sopenharmony_ci STM32_GATE(_id, _name, _parent, _flags,\ 12278c2ecf20Sopenharmony_ci _STM32_MGATE(_mgate)) 12288c2ecf20Sopenharmony_ci 12298c2ecf20Sopenharmony_ci#define _STM32_DIV(_div_offset, _div_shift, _div_width,\ 12308c2ecf20Sopenharmony_ci _div_flags, _div_table, _ops)\ 12318c2ecf20Sopenharmony_ci .div = &(struct stm32_div_cfg) {\ 12328c2ecf20Sopenharmony_ci &(struct div_cfg) {\ 12338c2ecf20Sopenharmony_ci .reg_off = _div_offset,\ 12348c2ecf20Sopenharmony_ci .shift = _div_shift,\ 12358c2ecf20Sopenharmony_ci .width = _div_width,\ 12368c2ecf20Sopenharmony_ci .div_flags = _div_flags,\ 12378c2ecf20Sopenharmony_ci .table = _div_table,\ 12388c2ecf20Sopenharmony_ci },\ 12398c2ecf20Sopenharmony_ci .ops = _ops,\ 12408c2ecf20Sopenharmony_ci } 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci#define _DIV(_div_offset, _div_shift, _div_width, _div_flags, _div_table)\ 12438c2ecf20Sopenharmony_ci _STM32_DIV(_div_offset, _div_shift, _div_width,\ 12448c2ecf20Sopenharmony_ci _div_flags, _div_table, NULL)\ 12458c2ecf20Sopenharmony_ci 12468c2ecf20Sopenharmony_ci#define _STM32_MUX(_offset, _shift, _width, _mux_flags, _mmux, _ops)\ 12478c2ecf20Sopenharmony_ci .mux = &(struct stm32_mux_cfg) {\ 12488c2ecf20Sopenharmony_ci &(struct mux_cfg) {\ 12498c2ecf20Sopenharmony_ci .reg_off = _offset,\ 12508c2ecf20Sopenharmony_ci .shift = _shift,\ 12518c2ecf20Sopenharmony_ci .width = _width,\ 12528c2ecf20Sopenharmony_ci .mux_flags = _mux_flags,\ 12538c2ecf20Sopenharmony_ci .table = NULL,\ 12548c2ecf20Sopenharmony_ci },\ 12558c2ecf20Sopenharmony_ci .mmux = _mmux,\ 12568c2ecf20Sopenharmony_ci .ops = _ops,\ 12578c2ecf20Sopenharmony_ci } 12588c2ecf20Sopenharmony_ci 12598c2ecf20Sopenharmony_ci#define _MUX(_offset, _shift, _width, _mux_flags)\ 12608c2ecf20Sopenharmony_ci _STM32_MUX(_offset, _shift, _width, _mux_flags, NULL, NULL)\ 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_ci#define _MMUX(_mmux) .mux = &ker_mux_cfg[_mmux] 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci#define PARENT(_parent) ((const char *[]) { _parent}) 12658c2ecf20Sopenharmony_ci 12668c2ecf20Sopenharmony_ci#define _NO_MUX .mux = NULL 12678c2ecf20Sopenharmony_ci#define _NO_DIV .div = NULL 12688c2ecf20Sopenharmony_ci#define _NO_GATE .gate = NULL 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci#define COMPOSITE(_id, _name, _parents, _flags, _gate, _mux, _div)\ 12718c2ecf20Sopenharmony_ci{\ 12728c2ecf20Sopenharmony_ci .id = _id,\ 12738c2ecf20Sopenharmony_ci .name = _name,\ 12748c2ecf20Sopenharmony_ci .parent_names = _parents,\ 12758c2ecf20Sopenharmony_ci .num_parents = ARRAY_SIZE(_parents),\ 12768c2ecf20Sopenharmony_ci .flags = _flags,\ 12778c2ecf20Sopenharmony_ci .cfg = &(struct stm32_composite_cfg) {\ 12788c2ecf20Sopenharmony_ci _gate,\ 12798c2ecf20Sopenharmony_ci _mux,\ 12808c2ecf20Sopenharmony_ci _div,\ 12818c2ecf20Sopenharmony_ci },\ 12828c2ecf20Sopenharmony_ci .func = _clk_stm32_register_composite,\ 12838c2ecf20Sopenharmony_ci} 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci#define PCLK(_id, _name, _parent, _flags, _mgate)\ 12868c2ecf20Sopenharmony_ci MGATE_MP1(_id, _name, _parent, _flags, _mgate) 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci#define KCLK(_id, _name, _parents, _flags, _mgate, _mmux)\ 12898c2ecf20Sopenharmony_ci COMPOSITE(_id, _name, _parents, CLK_OPS_PARENT_ENABLE |\ 12908c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT | _flags,\ 12918c2ecf20Sopenharmony_ci _MGATE_MP1(_mgate),\ 12928c2ecf20Sopenharmony_ci _MMUX(_mmux),\ 12938c2ecf20Sopenharmony_ci _NO_DIV) 12948c2ecf20Sopenharmony_ci 12958c2ecf20Sopenharmony_cienum { 12968c2ecf20Sopenharmony_ci G_SAI1, 12978c2ecf20Sopenharmony_ci G_SAI2, 12988c2ecf20Sopenharmony_ci G_SAI3, 12998c2ecf20Sopenharmony_ci G_SAI4, 13008c2ecf20Sopenharmony_ci G_SPI1, 13018c2ecf20Sopenharmony_ci G_SPI2, 13028c2ecf20Sopenharmony_ci G_SPI3, 13038c2ecf20Sopenharmony_ci G_SPI4, 13048c2ecf20Sopenharmony_ci G_SPI5, 13058c2ecf20Sopenharmony_ci G_SPI6, 13068c2ecf20Sopenharmony_ci G_SPDIF, 13078c2ecf20Sopenharmony_ci G_I2C1, 13088c2ecf20Sopenharmony_ci G_I2C2, 13098c2ecf20Sopenharmony_ci G_I2C3, 13108c2ecf20Sopenharmony_ci G_I2C4, 13118c2ecf20Sopenharmony_ci G_I2C5, 13128c2ecf20Sopenharmony_ci G_I2C6, 13138c2ecf20Sopenharmony_ci G_USART2, 13148c2ecf20Sopenharmony_ci G_UART4, 13158c2ecf20Sopenharmony_ci G_USART3, 13168c2ecf20Sopenharmony_ci G_UART5, 13178c2ecf20Sopenharmony_ci G_USART1, 13188c2ecf20Sopenharmony_ci G_USART6, 13198c2ecf20Sopenharmony_ci G_UART7, 13208c2ecf20Sopenharmony_ci G_UART8, 13218c2ecf20Sopenharmony_ci G_LPTIM1, 13228c2ecf20Sopenharmony_ci G_LPTIM2, 13238c2ecf20Sopenharmony_ci G_LPTIM3, 13248c2ecf20Sopenharmony_ci G_LPTIM4, 13258c2ecf20Sopenharmony_ci G_LPTIM5, 13268c2ecf20Sopenharmony_ci G_LTDC, 13278c2ecf20Sopenharmony_ci G_DSI, 13288c2ecf20Sopenharmony_ci G_QSPI, 13298c2ecf20Sopenharmony_ci G_FMC, 13308c2ecf20Sopenharmony_ci G_SDMMC1, 13318c2ecf20Sopenharmony_ci G_SDMMC2, 13328c2ecf20Sopenharmony_ci G_SDMMC3, 13338c2ecf20Sopenharmony_ci G_USBO, 13348c2ecf20Sopenharmony_ci G_USBPHY, 13358c2ecf20Sopenharmony_ci G_RNG1, 13368c2ecf20Sopenharmony_ci G_RNG2, 13378c2ecf20Sopenharmony_ci G_FDCAN, 13388c2ecf20Sopenharmony_ci G_DAC12, 13398c2ecf20Sopenharmony_ci G_CEC, 13408c2ecf20Sopenharmony_ci G_ADC12, 13418c2ecf20Sopenharmony_ci G_GPU, 13428c2ecf20Sopenharmony_ci G_STGEN, 13438c2ecf20Sopenharmony_ci G_DFSDM, 13448c2ecf20Sopenharmony_ci G_ADFSDM, 13458c2ecf20Sopenharmony_ci G_TIM2, 13468c2ecf20Sopenharmony_ci G_TIM3, 13478c2ecf20Sopenharmony_ci G_TIM4, 13488c2ecf20Sopenharmony_ci G_TIM5, 13498c2ecf20Sopenharmony_ci G_TIM6, 13508c2ecf20Sopenharmony_ci G_TIM7, 13518c2ecf20Sopenharmony_ci G_TIM12, 13528c2ecf20Sopenharmony_ci G_TIM13, 13538c2ecf20Sopenharmony_ci G_TIM14, 13548c2ecf20Sopenharmony_ci G_MDIO, 13558c2ecf20Sopenharmony_ci G_TIM1, 13568c2ecf20Sopenharmony_ci G_TIM8, 13578c2ecf20Sopenharmony_ci G_TIM15, 13588c2ecf20Sopenharmony_ci G_TIM16, 13598c2ecf20Sopenharmony_ci G_TIM17, 13608c2ecf20Sopenharmony_ci G_SYSCFG, 13618c2ecf20Sopenharmony_ci G_VREF, 13628c2ecf20Sopenharmony_ci G_TMPSENS, 13638c2ecf20Sopenharmony_ci G_PMBCTRL, 13648c2ecf20Sopenharmony_ci G_HDP, 13658c2ecf20Sopenharmony_ci G_IWDG2, 13668c2ecf20Sopenharmony_ci G_STGENRO, 13678c2ecf20Sopenharmony_ci G_DMA1, 13688c2ecf20Sopenharmony_ci G_DMA2, 13698c2ecf20Sopenharmony_ci G_DMAMUX, 13708c2ecf20Sopenharmony_ci G_DCMI, 13718c2ecf20Sopenharmony_ci G_CRYP2, 13728c2ecf20Sopenharmony_ci G_HASH2, 13738c2ecf20Sopenharmony_ci G_CRC2, 13748c2ecf20Sopenharmony_ci G_HSEM, 13758c2ecf20Sopenharmony_ci G_IPCC, 13768c2ecf20Sopenharmony_ci G_GPIOA, 13778c2ecf20Sopenharmony_ci G_GPIOB, 13788c2ecf20Sopenharmony_ci G_GPIOC, 13798c2ecf20Sopenharmony_ci G_GPIOD, 13808c2ecf20Sopenharmony_ci G_GPIOE, 13818c2ecf20Sopenharmony_ci G_GPIOF, 13828c2ecf20Sopenharmony_ci G_GPIOG, 13838c2ecf20Sopenharmony_ci G_GPIOH, 13848c2ecf20Sopenharmony_ci G_GPIOI, 13858c2ecf20Sopenharmony_ci G_GPIOJ, 13868c2ecf20Sopenharmony_ci G_GPIOK, 13878c2ecf20Sopenharmony_ci G_MDMA, 13888c2ecf20Sopenharmony_ci G_ETHCK, 13898c2ecf20Sopenharmony_ci G_ETHTX, 13908c2ecf20Sopenharmony_ci G_ETHRX, 13918c2ecf20Sopenharmony_ci G_ETHMAC, 13928c2ecf20Sopenharmony_ci G_CRC1, 13938c2ecf20Sopenharmony_ci G_USBH, 13948c2ecf20Sopenharmony_ci G_ETHSTP, 13958c2ecf20Sopenharmony_ci G_RTCAPB, 13968c2ecf20Sopenharmony_ci G_TZC1, 13978c2ecf20Sopenharmony_ci G_TZC2, 13988c2ecf20Sopenharmony_ci G_TZPC, 13998c2ecf20Sopenharmony_ci G_IWDG1, 14008c2ecf20Sopenharmony_ci G_BSEC, 14018c2ecf20Sopenharmony_ci G_GPIOZ, 14028c2ecf20Sopenharmony_ci G_CRYP1, 14038c2ecf20Sopenharmony_ci G_HASH1, 14048c2ecf20Sopenharmony_ci G_BKPSRAM, 14058c2ecf20Sopenharmony_ci G_DDRPERFM, 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_ci G_LAST 14088c2ecf20Sopenharmony_ci}; 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_cistatic struct stm32_mgate mp1_mgate[G_LAST]; 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci#define _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\ 14138c2ecf20Sopenharmony_ci _mgate, _ops)\ 14148c2ecf20Sopenharmony_ci [_id] = {\ 14158c2ecf20Sopenharmony_ci &(struct gate_cfg) {\ 14168c2ecf20Sopenharmony_ci .reg_off = _gate_offset,\ 14178c2ecf20Sopenharmony_ci .bit_idx = _gate_bit_idx,\ 14188c2ecf20Sopenharmony_ci .gate_flags = _gate_flags,\ 14198c2ecf20Sopenharmony_ci },\ 14208c2ecf20Sopenharmony_ci .mgate = _mgate,\ 14218c2ecf20Sopenharmony_ci .ops = _ops,\ 14228c2ecf20Sopenharmony_ci } 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ci#define K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags)\ 14258c2ecf20Sopenharmony_ci _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\ 14268c2ecf20Sopenharmony_ci NULL, &mp1_gate_clk_ops) 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci#define K_MGATE(_id, _gate_offset, _gate_bit_idx, _gate_flags)\ 14298c2ecf20Sopenharmony_ci _K_GATE(_id, _gate_offset, _gate_bit_idx, _gate_flags,\ 14308c2ecf20Sopenharmony_ci &mp1_mgate[_id], &mp1_mgate_clk_ops) 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ci/* Peripheral gates */ 14338c2ecf20Sopenharmony_cistatic struct stm32_gate_cfg per_gate_cfg[G_LAST] = { 14348c2ecf20Sopenharmony_ci /* Multi gates */ 14358c2ecf20Sopenharmony_ci K_GATE(G_MDIO, RCC_APB1ENSETR, 31, 0), 14368c2ecf20Sopenharmony_ci K_MGATE(G_DAC12, RCC_APB1ENSETR, 29, 0), 14378c2ecf20Sopenharmony_ci K_MGATE(G_CEC, RCC_APB1ENSETR, 27, 0), 14388c2ecf20Sopenharmony_ci K_MGATE(G_SPDIF, RCC_APB1ENSETR, 26, 0), 14398c2ecf20Sopenharmony_ci K_MGATE(G_I2C5, RCC_APB1ENSETR, 24, 0), 14408c2ecf20Sopenharmony_ci K_MGATE(G_I2C3, RCC_APB1ENSETR, 23, 0), 14418c2ecf20Sopenharmony_ci K_MGATE(G_I2C2, RCC_APB1ENSETR, 22, 0), 14428c2ecf20Sopenharmony_ci K_MGATE(G_I2C1, RCC_APB1ENSETR, 21, 0), 14438c2ecf20Sopenharmony_ci K_MGATE(G_UART8, RCC_APB1ENSETR, 19, 0), 14448c2ecf20Sopenharmony_ci K_MGATE(G_UART7, RCC_APB1ENSETR, 18, 0), 14458c2ecf20Sopenharmony_ci K_MGATE(G_UART5, RCC_APB1ENSETR, 17, 0), 14468c2ecf20Sopenharmony_ci K_MGATE(G_UART4, RCC_APB1ENSETR, 16, 0), 14478c2ecf20Sopenharmony_ci K_MGATE(G_USART3, RCC_APB1ENSETR, 15, 0), 14488c2ecf20Sopenharmony_ci K_MGATE(G_USART2, RCC_APB1ENSETR, 14, 0), 14498c2ecf20Sopenharmony_ci K_MGATE(G_SPI3, RCC_APB1ENSETR, 12, 0), 14508c2ecf20Sopenharmony_ci K_MGATE(G_SPI2, RCC_APB1ENSETR, 11, 0), 14518c2ecf20Sopenharmony_ci K_MGATE(G_LPTIM1, RCC_APB1ENSETR, 9, 0), 14528c2ecf20Sopenharmony_ci K_GATE(G_TIM14, RCC_APB1ENSETR, 8, 0), 14538c2ecf20Sopenharmony_ci K_GATE(G_TIM13, RCC_APB1ENSETR, 7, 0), 14548c2ecf20Sopenharmony_ci K_GATE(G_TIM12, RCC_APB1ENSETR, 6, 0), 14558c2ecf20Sopenharmony_ci K_GATE(G_TIM7, RCC_APB1ENSETR, 5, 0), 14568c2ecf20Sopenharmony_ci K_GATE(G_TIM6, RCC_APB1ENSETR, 4, 0), 14578c2ecf20Sopenharmony_ci K_GATE(G_TIM5, RCC_APB1ENSETR, 3, 0), 14588c2ecf20Sopenharmony_ci K_GATE(G_TIM4, RCC_APB1ENSETR, 2, 0), 14598c2ecf20Sopenharmony_ci K_GATE(G_TIM3, RCC_APB1ENSETR, 1, 0), 14608c2ecf20Sopenharmony_ci K_GATE(G_TIM2, RCC_APB1ENSETR, 0, 0), 14618c2ecf20Sopenharmony_ci 14628c2ecf20Sopenharmony_ci K_MGATE(G_FDCAN, RCC_APB2ENSETR, 24, 0), 14638c2ecf20Sopenharmony_ci K_GATE(G_ADFSDM, RCC_APB2ENSETR, 21, 0), 14648c2ecf20Sopenharmony_ci K_GATE(G_DFSDM, RCC_APB2ENSETR, 20, 0), 14658c2ecf20Sopenharmony_ci K_MGATE(G_SAI3, RCC_APB2ENSETR, 18, 0), 14668c2ecf20Sopenharmony_ci K_MGATE(G_SAI2, RCC_APB2ENSETR, 17, 0), 14678c2ecf20Sopenharmony_ci K_MGATE(G_SAI1, RCC_APB2ENSETR, 16, 0), 14688c2ecf20Sopenharmony_ci K_MGATE(G_USART6, RCC_APB2ENSETR, 13, 0), 14698c2ecf20Sopenharmony_ci K_MGATE(G_SPI5, RCC_APB2ENSETR, 10, 0), 14708c2ecf20Sopenharmony_ci K_MGATE(G_SPI4, RCC_APB2ENSETR, 9, 0), 14718c2ecf20Sopenharmony_ci K_MGATE(G_SPI1, RCC_APB2ENSETR, 8, 0), 14728c2ecf20Sopenharmony_ci K_GATE(G_TIM17, RCC_APB2ENSETR, 4, 0), 14738c2ecf20Sopenharmony_ci K_GATE(G_TIM16, RCC_APB2ENSETR, 3, 0), 14748c2ecf20Sopenharmony_ci K_GATE(G_TIM15, RCC_APB2ENSETR, 2, 0), 14758c2ecf20Sopenharmony_ci K_GATE(G_TIM8, RCC_APB2ENSETR, 1, 0), 14768c2ecf20Sopenharmony_ci K_GATE(G_TIM1, RCC_APB2ENSETR, 0, 0), 14778c2ecf20Sopenharmony_ci 14788c2ecf20Sopenharmony_ci K_GATE(G_HDP, RCC_APB3ENSETR, 20, 0), 14798c2ecf20Sopenharmony_ci K_GATE(G_PMBCTRL, RCC_APB3ENSETR, 17, 0), 14808c2ecf20Sopenharmony_ci K_GATE(G_TMPSENS, RCC_APB3ENSETR, 16, 0), 14818c2ecf20Sopenharmony_ci K_GATE(G_VREF, RCC_APB3ENSETR, 13, 0), 14828c2ecf20Sopenharmony_ci K_GATE(G_SYSCFG, RCC_APB3ENSETR, 11, 0), 14838c2ecf20Sopenharmony_ci K_MGATE(G_SAI4, RCC_APB3ENSETR, 8, 0), 14848c2ecf20Sopenharmony_ci K_MGATE(G_LPTIM5, RCC_APB3ENSETR, 3, 0), 14858c2ecf20Sopenharmony_ci K_MGATE(G_LPTIM4, RCC_APB3ENSETR, 2, 0), 14868c2ecf20Sopenharmony_ci K_MGATE(G_LPTIM3, RCC_APB3ENSETR, 1, 0), 14878c2ecf20Sopenharmony_ci K_MGATE(G_LPTIM2, RCC_APB3ENSETR, 0, 0), 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_ci K_GATE(G_STGENRO, RCC_APB4ENSETR, 20, 0), 14908c2ecf20Sopenharmony_ci K_MGATE(G_USBPHY, RCC_APB4ENSETR, 16, 0), 14918c2ecf20Sopenharmony_ci K_GATE(G_IWDG2, RCC_APB4ENSETR, 15, 0), 14928c2ecf20Sopenharmony_ci K_GATE(G_DDRPERFM, RCC_APB4ENSETR, 8, 0), 14938c2ecf20Sopenharmony_ci K_MGATE(G_DSI, RCC_APB4ENSETR, 4, 0), 14948c2ecf20Sopenharmony_ci K_MGATE(G_LTDC, RCC_APB4ENSETR, 0, 0), 14958c2ecf20Sopenharmony_ci 14968c2ecf20Sopenharmony_ci K_GATE(G_STGEN, RCC_APB5ENSETR, 20, 0), 14978c2ecf20Sopenharmony_ci K_GATE(G_BSEC, RCC_APB5ENSETR, 16, 0), 14988c2ecf20Sopenharmony_ci K_GATE(G_IWDG1, RCC_APB5ENSETR, 15, 0), 14998c2ecf20Sopenharmony_ci K_GATE(G_TZPC, RCC_APB5ENSETR, 13, 0), 15008c2ecf20Sopenharmony_ci K_GATE(G_TZC2, RCC_APB5ENSETR, 12, 0), 15018c2ecf20Sopenharmony_ci K_GATE(G_TZC1, RCC_APB5ENSETR, 11, 0), 15028c2ecf20Sopenharmony_ci K_GATE(G_RTCAPB, RCC_APB5ENSETR, 8, 0), 15038c2ecf20Sopenharmony_ci K_MGATE(G_USART1, RCC_APB5ENSETR, 4, 0), 15048c2ecf20Sopenharmony_ci K_MGATE(G_I2C6, RCC_APB5ENSETR, 3, 0), 15058c2ecf20Sopenharmony_ci K_MGATE(G_I2C4, RCC_APB5ENSETR, 2, 0), 15068c2ecf20Sopenharmony_ci K_MGATE(G_SPI6, RCC_APB5ENSETR, 0, 0), 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci K_MGATE(G_SDMMC3, RCC_AHB2ENSETR, 16, 0), 15098c2ecf20Sopenharmony_ci K_MGATE(G_USBO, RCC_AHB2ENSETR, 8, 0), 15108c2ecf20Sopenharmony_ci K_MGATE(G_ADC12, RCC_AHB2ENSETR, 5, 0), 15118c2ecf20Sopenharmony_ci K_GATE(G_DMAMUX, RCC_AHB2ENSETR, 2, 0), 15128c2ecf20Sopenharmony_ci K_GATE(G_DMA2, RCC_AHB2ENSETR, 1, 0), 15138c2ecf20Sopenharmony_ci K_GATE(G_DMA1, RCC_AHB2ENSETR, 0, 0), 15148c2ecf20Sopenharmony_ci 15158c2ecf20Sopenharmony_ci K_GATE(G_IPCC, RCC_AHB3ENSETR, 12, 0), 15168c2ecf20Sopenharmony_ci K_GATE(G_HSEM, RCC_AHB3ENSETR, 11, 0), 15178c2ecf20Sopenharmony_ci K_GATE(G_CRC2, RCC_AHB3ENSETR, 7, 0), 15188c2ecf20Sopenharmony_ci K_MGATE(G_RNG2, RCC_AHB3ENSETR, 6, 0), 15198c2ecf20Sopenharmony_ci K_GATE(G_HASH2, RCC_AHB3ENSETR, 5, 0), 15208c2ecf20Sopenharmony_ci K_GATE(G_CRYP2, RCC_AHB3ENSETR, 4, 0), 15218c2ecf20Sopenharmony_ci K_GATE(G_DCMI, RCC_AHB3ENSETR, 0, 0), 15228c2ecf20Sopenharmony_ci 15238c2ecf20Sopenharmony_ci K_GATE(G_GPIOK, RCC_AHB4ENSETR, 10, 0), 15248c2ecf20Sopenharmony_ci K_GATE(G_GPIOJ, RCC_AHB4ENSETR, 9, 0), 15258c2ecf20Sopenharmony_ci K_GATE(G_GPIOI, RCC_AHB4ENSETR, 8, 0), 15268c2ecf20Sopenharmony_ci K_GATE(G_GPIOH, RCC_AHB4ENSETR, 7, 0), 15278c2ecf20Sopenharmony_ci K_GATE(G_GPIOG, RCC_AHB4ENSETR, 6, 0), 15288c2ecf20Sopenharmony_ci K_GATE(G_GPIOF, RCC_AHB4ENSETR, 5, 0), 15298c2ecf20Sopenharmony_ci K_GATE(G_GPIOE, RCC_AHB4ENSETR, 4, 0), 15308c2ecf20Sopenharmony_ci K_GATE(G_GPIOD, RCC_AHB4ENSETR, 3, 0), 15318c2ecf20Sopenharmony_ci K_GATE(G_GPIOC, RCC_AHB4ENSETR, 2, 0), 15328c2ecf20Sopenharmony_ci K_GATE(G_GPIOB, RCC_AHB4ENSETR, 1, 0), 15338c2ecf20Sopenharmony_ci K_GATE(G_GPIOA, RCC_AHB4ENSETR, 0, 0), 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci K_GATE(G_BKPSRAM, RCC_AHB5ENSETR, 8, 0), 15368c2ecf20Sopenharmony_ci K_MGATE(G_RNG1, RCC_AHB5ENSETR, 6, 0), 15378c2ecf20Sopenharmony_ci K_GATE(G_HASH1, RCC_AHB5ENSETR, 5, 0), 15388c2ecf20Sopenharmony_ci K_GATE(G_CRYP1, RCC_AHB5ENSETR, 4, 0), 15398c2ecf20Sopenharmony_ci K_GATE(G_GPIOZ, RCC_AHB5ENSETR, 0, 0), 15408c2ecf20Sopenharmony_ci 15418c2ecf20Sopenharmony_ci K_GATE(G_USBH, RCC_AHB6ENSETR, 24, 0), 15428c2ecf20Sopenharmony_ci K_GATE(G_CRC1, RCC_AHB6ENSETR, 20, 0), 15438c2ecf20Sopenharmony_ci K_MGATE(G_SDMMC2, RCC_AHB6ENSETR, 17, 0), 15448c2ecf20Sopenharmony_ci K_MGATE(G_SDMMC1, RCC_AHB6ENSETR, 16, 0), 15458c2ecf20Sopenharmony_ci K_MGATE(G_QSPI, RCC_AHB6ENSETR, 14, 0), 15468c2ecf20Sopenharmony_ci K_MGATE(G_FMC, RCC_AHB6ENSETR, 12, 0), 15478c2ecf20Sopenharmony_ci K_GATE(G_ETHMAC, RCC_AHB6ENSETR, 10, 0), 15488c2ecf20Sopenharmony_ci K_GATE(G_ETHRX, RCC_AHB6ENSETR, 9, 0), 15498c2ecf20Sopenharmony_ci K_GATE(G_ETHTX, RCC_AHB6ENSETR, 8, 0), 15508c2ecf20Sopenharmony_ci K_GATE(G_ETHCK, RCC_AHB6ENSETR, 7, 0), 15518c2ecf20Sopenharmony_ci K_MGATE(G_GPU, RCC_AHB6ENSETR, 5, 0), 15528c2ecf20Sopenharmony_ci K_GATE(G_MDMA, RCC_AHB6ENSETR, 0, 0), 15538c2ecf20Sopenharmony_ci K_GATE(G_ETHSTP, RCC_AHB6LPENSETR, 11, 0), 15548c2ecf20Sopenharmony_ci}; 15558c2ecf20Sopenharmony_ci 15568c2ecf20Sopenharmony_cienum { 15578c2ecf20Sopenharmony_ci M_SDMMC12, 15588c2ecf20Sopenharmony_ci M_SDMMC3, 15598c2ecf20Sopenharmony_ci M_FMC, 15608c2ecf20Sopenharmony_ci M_QSPI, 15618c2ecf20Sopenharmony_ci M_RNG1, 15628c2ecf20Sopenharmony_ci M_RNG2, 15638c2ecf20Sopenharmony_ci M_USBPHY, 15648c2ecf20Sopenharmony_ci M_USBO, 15658c2ecf20Sopenharmony_ci M_STGEN, 15668c2ecf20Sopenharmony_ci M_SPDIF, 15678c2ecf20Sopenharmony_ci M_SPI1, 15688c2ecf20Sopenharmony_ci M_SPI23, 15698c2ecf20Sopenharmony_ci M_SPI45, 15708c2ecf20Sopenharmony_ci M_SPI6, 15718c2ecf20Sopenharmony_ci M_CEC, 15728c2ecf20Sopenharmony_ci M_I2C12, 15738c2ecf20Sopenharmony_ci M_I2C35, 15748c2ecf20Sopenharmony_ci M_I2C46, 15758c2ecf20Sopenharmony_ci M_LPTIM1, 15768c2ecf20Sopenharmony_ci M_LPTIM23, 15778c2ecf20Sopenharmony_ci M_LPTIM45, 15788c2ecf20Sopenharmony_ci M_USART1, 15798c2ecf20Sopenharmony_ci M_UART24, 15808c2ecf20Sopenharmony_ci M_UART35, 15818c2ecf20Sopenharmony_ci M_USART6, 15828c2ecf20Sopenharmony_ci M_UART78, 15838c2ecf20Sopenharmony_ci M_SAI1, 15848c2ecf20Sopenharmony_ci M_SAI2, 15858c2ecf20Sopenharmony_ci M_SAI3, 15868c2ecf20Sopenharmony_ci M_SAI4, 15878c2ecf20Sopenharmony_ci M_DSI, 15888c2ecf20Sopenharmony_ci M_FDCAN, 15898c2ecf20Sopenharmony_ci M_ADC12, 15908c2ecf20Sopenharmony_ci M_ETHCK, 15918c2ecf20Sopenharmony_ci M_CKPER, 15928c2ecf20Sopenharmony_ci M_LAST 15938c2ecf20Sopenharmony_ci}; 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_cistatic struct stm32_mmux ker_mux[M_LAST]; 15968c2ecf20Sopenharmony_ci 15978c2ecf20Sopenharmony_ci#define _K_MUX(_id, _offset, _shift, _width, _mux_flags, _mmux, _ops)\ 15988c2ecf20Sopenharmony_ci [_id] = {\ 15998c2ecf20Sopenharmony_ci &(struct mux_cfg) {\ 16008c2ecf20Sopenharmony_ci .reg_off = _offset,\ 16018c2ecf20Sopenharmony_ci .shift = _shift,\ 16028c2ecf20Sopenharmony_ci .width = _width,\ 16038c2ecf20Sopenharmony_ci .mux_flags = _mux_flags,\ 16048c2ecf20Sopenharmony_ci .table = NULL,\ 16058c2ecf20Sopenharmony_ci },\ 16068c2ecf20Sopenharmony_ci .mmux = _mmux,\ 16078c2ecf20Sopenharmony_ci .ops = _ops,\ 16088c2ecf20Sopenharmony_ci } 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci#define K_MUX(_id, _offset, _shift, _width, _mux_flags)\ 16118c2ecf20Sopenharmony_ci _K_MUX(_id, _offset, _shift, _width, _mux_flags,\ 16128c2ecf20Sopenharmony_ci NULL, NULL) 16138c2ecf20Sopenharmony_ci 16148c2ecf20Sopenharmony_ci#define K_MMUX(_id, _offset, _shift, _width, _mux_flags)\ 16158c2ecf20Sopenharmony_ci _K_MUX(_id, _offset, _shift, _width, _mux_flags,\ 16168c2ecf20Sopenharmony_ci &ker_mux[_id], &clk_mmux_ops) 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_cistatic const struct stm32_mux_cfg ker_mux_cfg[M_LAST] = { 16198c2ecf20Sopenharmony_ci /* Kernel multi mux */ 16208c2ecf20Sopenharmony_ci K_MMUX(M_SDMMC12, RCC_SDMMC12CKSELR, 0, 3, 0), 16218c2ecf20Sopenharmony_ci K_MMUX(M_SPI23, RCC_SPI2S23CKSELR, 0, 3, 0), 16228c2ecf20Sopenharmony_ci K_MMUX(M_SPI45, RCC_SPI2S45CKSELR, 0, 3, 0), 16238c2ecf20Sopenharmony_ci K_MMUX(M_I2C12, RCC_I2C12CKSELR, 0, 3, 0), 16248c2ecf20Sopenharmony_ci K_MMUX(M_I2C35, RCC_I2C35CKSELR, 0, 3, 0), 16258c2ecf20Sopenharmony_ci K_MMUX(M_LPTIM23, RCC_LPTIM23CKSELR, 0, 3, 0), 16268c2ecf20Sopenharmony_ci K_MMUX(M_LPTIM45, RCC_LPTIM45CKSELR, 0, 3, 0), 16278c2ecf20Sopenharmony_ci K_MMUX(M_UART24, RCC_UART24CKSELR, 0, 3, 0), 16288c2ecf20Sopenharmony_ci K_MMUX(M_UART35, RCC_UART35CKSELR, 0, 3, 0), 16298c2ecf20Sopenharmony_ci K_MMUX(M_UART78, RCC_UART78CKSELR, 0, 3, 0), 16308c2ecf20Sopenharmony_ci K_MMUX(M_SAI1, RCC_SAI1CKSELR, 0, 3, 0), 16318c2ecf20Sopenharmony_ci K_MMUX(M_ETHCK, RCC_ETHCKSELR, 0, 2, 0), 16328c2ecf20Sopenharmony_ci K_MMUX(M_I2C46, RCC_I2C46CKSELR, 0, 3, 0), 16338c2ecf20Sopenharmony_ci 16348c2ecf20Sopenharmony_ci /* Kernel simple mux */ 16358c2ecf20Sopenharmony_ci K_MUX(M_RNG2, RCC_RNG2CKSELR, 0, 2, 0), 16368c2ecf20Sopenharmony_ci K_MUX(M_SDMMC3, RCC_SDMMC3CKSELR, 0, 3, 0), 16378c2ecf20Sopenharmony_ci K_MUX(M_FMC, RCC_FMCCKSELR, 0, 2, 0), 16388c2ecf20Sopenharmony_ci K_MUX(M_QSPI, RCC_QSPICKSELR, 0, 2, 0), 16398c2ecf20Sopenharmony_ci K_MUX(M_USBPHY, RCC_USBCKSELR, 0, 2, 0), 16408c2ecf20Sopenharmony_ci K_MUX(M_USBO, RCC_USBCKSELR, 4, 1, 0), 16418c2ecf20Sopenharmony_ci K_MUX(M_SPDIF, RCC_SPDIFCKSELR, 0, 2, 0), 16428c2ecf20Sopenharmony_ci K_MUX(M_SPI1, RCC_SPI2S1CKSELR, 0, 3, 0), 16438c2ecf20Sopenharmony_ci K_MUX(M_CEC, RCC_CECCKSELR, 0, 2, 0), 16448c2ecf20Sopenharmony_ci K_MUX(M_LPTIM1, RCC_LPTIM1CKSELR, 0, 3, 0), 16458c2ecf20Sopenharmony_ci K_MUX(M_USART6, RCC_UART6CKSELR, 0, 3, 0), 16468c2ecf20Sopenharmony_ci K_MUX(M_FDCAN, RCC_FDCANCKSELR, 0, 2, 0), 16478c2ecf20Sopenharmony_ci K_MUX(M_SAI2, RCC_SAI2CKSELR, 0, 3, 0), 16488c2ecf20Sopenharmony_ci K_MUX(M_SAI3, RCC_SAI3CKSELR, 0, 3, 0), 16498c2ecf20Sopenharmony_ci K_MUX(M_SAI4, RCC_SAI4CKSELR, 0, 3, 0), 16508c2ecf20Sopenharmony_ci K_MUX(M_ADC12, RCC_ADCCKSELR, 0, 2, 0), 16518c2ecf20Sopenharmony_ci K_MUX(M_DSI, RCC_DSICKSELR, 0, 1, 0), 16528c2ecf20Sopenharmony_ci K_MUX(M_CKPER, RCC_CPERCKSELR, 0, 2, 0), 16538c2ecf20Sopenharmony_ci K_MUX(M_RNG1, RCC_RNG1CKSELR, 0, 2, 0), 16548c2ecf20Sopenharmony_ci K_MUX(M_STGEN, RCC_STGENCKSELR, 0, 2, 0), 16558c2ecf20Sopenharmony_ci K_MUX(M_USART1, RCC_UART1CKSELR, 0, 3, 0), 16568c2ecf20Sopenharmony_ci K_MUX(M_SPI6, RCC_SPI6CKSELR, 0, 3, 0), 16578c2ecf20Sopenharmony_ci}; 16588c2ecf20Sopenharmony_ci 16598c2ecf20Sopenharmony_cistatic const struct clock_config stm32mp1_clock_cfg[] = { 16608c2ecf20Sopenharmony_ci /* Oscillator divider */ 16618c2ecf20Sopenharmony_ci DIV(NO_ID, "clk-hsi-div", "clk-hsi", CLK_DIVIDER_POWER_OF_TWO, 16628c2ecf20Sopenharmony_ci RCC_HSICFGR, 0, 2, CLK_DIVIDER_READ_ONLY), 16638c2ecf20Sopenharmony_ci 16648c2ecf20Sopenharmony_ci /* External / Internal Oscillators */ 16658c2ecf20Sopenharmony_ci GATE_MP1(CK_HSE, "ck_hse", "clk-hse", 0, RCC_OCENSETR, 8, 0), 16668c2ecf20Sopenharmony_ci /* ck_csi is used by IO compensation and should be critical */ 16678c2ecf20Sopenharmony_ci GATE_MP1(CK_CSI, "ck_csi", "clk-csi", CLK_IS_CRITICAL, 16688c2ecf20Sopenharmony_ci RCC_OCENSETR, 4, 0), 16698c2ecf20Sopenharmony_ci GATE_MP1(CK_HSI, "ck_hsi", "clk-hsi-div", 0, RCC_OCENSETR, 0, 0), 16708c2ecf20Sopenharmony_ci GATE(CK_LSI, "ck_lsi", "clk-lsi", 0, RCC_RDLSICR, 0, 0), 16718c2ecf20Sopenharmony_ci GATE(CK_LSE, "ck_lse", "clk-lse", 0, RCC_BDCR, 0, 0), 16728c2ecf20Sopenharmony_ci 16738c2ecf20Sopenharmony_ci FIXED_FACTOR(CK_HSE_DIV2, "clk-hse-div2", "ck_hse", 0, 1, 2), 16748c2ecf20Sopenharmony_ci 16758c2ecf20Sopenharmony_ci /* ref clock pll */ 16768c2ecf20Sopenharmony_ci MUX(NO_ID, "ref1", ref12_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK12SELR, 16778c2ecf20Sopenharmony_ci 0, 2, CLK_MUX_READ_ONLY), 16788c2ecf20Sopenharmony_ci 16798c2ecf20Sopenharmony_ci MUX(NO_ID, "ref3", ref3_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK3SELR, 16808c2ecf20Sopenharmony_ci 0, 2, CLK_MUX_READ_ONLY), 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci MUX(NO_ID, "ref4", ref4_parents, CLK_OPS_PARENT_ENABLE, RCC_RCK4SELR, 16838c2ecf20Sopenharmony_ci 0, 2, CLK_MUX_READ_ONLY), 16848c2ecf20Sopenharmony_ci 16858c2ecf20Sopenharmony_ci /* PLLs */ 16868c2ecf20Sopenharmony_ci PLL(PLL1, "pll1", "ref1", CLK_IGNORE_UNUSED, RCC_PLL1CR), 16878c2ecf20Sopenharmony_ci PLL(PLL2, "pll2", "ref1", CLK_IGNORE_UNUSED, RCC_PLL2CR), 16888c2ecf20Sopenharmony_ci PLL(PLL3, "pll3", "ref3", CLK_IGNORE_UNUSED, RCC_PLL3CR), 16898c2ecf20Sopenharmony_ci PLL(PLL4, "pll4", "ref4", CLK_IGNORE_UNUSED, RCC_PLL4CR), 16908c2ecf20Sopenharmony_ci 16918c2ecf20Sopenharmony_ci /* ODF */ 16928c2ecf20Sopenharmony_ci COMPOSITE(PLL1_P, "pll1_p", PARENT("pll1"), 0, 16938c2ecf20Sopenharmony_ci _GATE(RCC_PLL1CR, 4, 0), 16948c2ecf20Sopenharmony_ci _NO_MUX, 16958c2ecf20Sopenharmony_ci _DIV(RCC_PLL1CFGR2, 0, 7, 0, NULL)), 16968c2ecf20Sopenharmony_ci 16978c2ecf20Sopenharmony_ci COMPOSITE(PLL2_P, "pll2_p", PARENT("pll2"), 0, 16988c2ecf20Sopenharmony_ci _GATE(RCC_PLL2CR, 4, 0), 16998c2ecf20Sopenharmony_ci _NO_MUX, 17008c2ecf20Sopenharmony_ci _DIV(RCC_PLL2CFGR2, 0, 7, 0, NULL)), 17018c2ecf20Sopenharmony_ci 17028c2ecf20Sopenharmony_ci COMPOSITE(PLL2_Q, "pll2_q", PARENT("pll2"), 0, 17038c2ecf20Sopenharmony_ci _GATE(RCC_PLL2CR, 5, 0), 17048c2ecf20Sopenharmony_ci _NO_MUX, 17058c2ecf20Sopenharmony_ci _DIV(RCC_PLL2CFGR2, 8, 7, 0, NULL)), 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci COMPOSITE(PLL2_R, "pll2_r", PARENT("pll2"), CLK_IS_CRITICAL, 17088c2ecf20Sopenharmony_ci _GATE(RCC_PLL2CR, 6, 0), 17098c2ecf20Sopenharmony_ci _NO_MUX, 17108c2ecf20Sopenharmony_ci _DIV(RCC_PLL2CFGR2, 16, 7, 0, NULL)), 17118c2ecf20Sopenharmony_ci 17128c2ecf20Sopenharmony_ci COMPOSITE(PLL3_P, "pll3_p", PARENT("pll3"), 0, 17138c2ecf20Sopenharmony_ci _GATE(RCC_PLL3CR, 4, 0), 17148c2ecf20Sopenharmony_ci _NO_MUX, 17158c2ecf20Sopenharmony_ci _DIV(RCC_PLL3CFGR2, 0, 7, 0, NULL)), 17168c2ecf20Sopenharmony_ci 17178c2ecf20Sopenharmony_ci COMPOSITE(PLL3_Q, "pll3_q", PARENT("pll3"), 0, 17188c2ecf20Sopenharmony_ci _GATE(RCC_PLL3CR, 5, 0), 17198c2ecf20Sopenharmony_ci _NO_MUX, 17208c2ecf20Sopenharmony_ci _DIV(RCC_PLL3CFGR2, 8, 7, 0, NULL)), 17218c2ecf20Sopenharmony_ci 17228c2ecf20Sopenharmony_ci COMPOSITE(PLL3_R, "pll3_r", PARENT("pll3"), 0, 17238c2ecf20Sopenharmony_ci _GATE(RCC_PLL3CR, 6, 0), 17248c2ecf20Sopenharmony_ci _NO_MUX, 17258c2ecf20Sopenharmony_ci _DIV(RCC_PLL3CFGR2, 16, 7, 0, NULL)), 17268c2ecf20Sopenharmony_ci 17278c2ecf20Sopenharmony_ci COMPOSITE(PLL4_P, "pll4_p", PARENT("pll4"), 0, 17288c2ecf20Sopenharmony_ci _GATE(RCC_PLL4CR, 4, 0), 17298c2ecf20Sopenharmony_ci _NO_MUX, 17308c2ecf20Sopenharmony_ci _DIV(RCC_PLL4CFGR2, 0, 7, 0, NULL)), 17318c2ecf20Sopenharmony_ci 17328c2ecf20Sopenharmony_ci COMPOSITE(PLL4_Q, "pll4_q", PARENT("pll4"), 0, 17338c2ecf20Sopenharmony_ci _GATE(RCC_PLL4CR, 5, 0), 17348c2ecf20Sopenharmony_ci _NO_MUX, 17358c2ecf20Sopenharmony_ci _DIV(RCC_PLL4CFGR2, 8, 7, 0, NULL)), 17368c2ecf20Sopenharmony_ci 17378c2ecf20Sopenharmony_ci COMPOSITE(PLL4_R, "pll4_r", PARENT("pll4"), 0, 17388c2ecf20Sopenharmony_ci _GATE(RCC_PLL4CR, 6, 0), 17398c2ecf20Sopenharmony_ci _NO_MUX, 17408c2ecf20Sopenharmony_ci _DIV(RCC_PLL4CFGR2, 16, 7, 0, NULL)), 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci /* MUX system clocks */ 17438c2ecf20Sopenharmony_ci MUX(CK_PER, "ck_per", per_src, CLK_OPS_PARENT_ENABLE, 17448c2ecf20Sopenharmony_ci RCC_CPERCKSELR, 0, 2, 0), 17458c2ecf20Sopenharmony_ci 17468c2ecf20Sopenharmony_ci MUX(CK_MPU, "ck_mpu", cpu_src, CLK_OPS_PARENT_ENABLE | 17478c2ecf20Sopenharmony_ci CLK_IS_CRITICAL, RCC_MPCKSELR, 0, 2, 0), 17488c2ecf20Sopenharmony_ci 17498c2ecf20Sopenharmony_ci COMPOSITE(CK_AXI, "ck_axi", axi_src, CLK_IS_CRITICAL | 17508c2ecf20Sopenharmony_ci CLK_OPS_PARENT_ENABLE, 17518c2ecf20Sopenharmony_ci _NO_GATE, 17528c2ecf20Sopenharmony_ci _MUX(RCC_ASSCKSELR, 0, 2, 0), 17538c2ecf20Sopenharmony_ci _DIV(RCC_AXIDIVR, 0, 3, 0, axi_div_table)), 17548c2ecf20Sopenharmony_ci 17558c2ecf20Sopenharmony_ci COMPOSITE(CK_MCU, "ck_mcu", mcu_src, CLK_IS_CRITICAL | 17568c2ecf20Sopenharmony_ci CLK_OPS_PARENT_ENABLE, 17578c2ecf20Sopenharmony_ci _NO_GATE, 17588c2ecf20Sopenharmony_ci _MUX(RCC_MSSCKSELR, 0, 2, 0), 17598c2ecf20Sopenharmony_ci _DIV(RCC_MCUDIVR, 0, 4, 0, mcu_div_table)), 17608c2ecf20Sopenharmony_ci 17618c2ecf20Sopenharmony_ci DIV_TABLE(NO_ID, "pclk1", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB1DIVR, 0, 17628c2ecf20Sopenharmony_ci 3, CLK_DIVIDER_READ_ONLY, apb_div_table), 17638c2ecf20Sopenharmony_ci 17648c2ecf20Sopenharmony_ci DIV_TABLE(NO_ID, "pclk2", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB2DIVR, 0, 17658c2ecf20Sopenharmony_ci 3, CLK_DIVIDER_READ_ONLY, apb_div_table), 17668c2ecf20Sopenharmony_ci 17678c2ecf20Sopenharmony_ci DIV_TABLE(NO_ID, "pclk3", "ck_mcu", CLK_IGNORE_UNUSED, RCC_APB3DIVR, 0, 17688c2ecf20Sopenharmony_ci 3, CLK_DIVIDER_READ_ONLY, apb_div_table), 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_ci DIV_TABLE(NO_ID, "pclk4", "ck_axi", CLK_IGNORE_UNUSED, RCC_APB4DIVR, 0, 17718c2ecf20Sopenharmony_ci 3, CLK_DIVIDER_READ_ONLY, apb_div_table), 17728c2ecf20Sopenharmony_ci 17738c2ecf20Sopenharmony_ci DIV_TABLE(NO_ID, "pclk5", "ck_axi", CLK_IGNORE_UNUSED, RCC_APB5DIVR, 0, 17748c2ecf20Sopenharmony_ci 3, CLK_DIVIDER_READ_ONLY, apb_div_table), 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci /* Kernel Timers */ 17778c2ecf20Sopenharmony_ci STM32_CKTIM("ck1_tim", "pclk1", 0, RCC_APB1DIVR, RCC_TIMG1PRER), 17788c2ecf20Sopenharmony_ci STM32_CKTIM("ck2_tim", "pclk2", 0, RCC_APB2DIVR, RCC_TIMG2PRER), 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci STM32_TIM(TIM2_K, "tim2_k", "ck1_tim", RCC_APB1ENSETR, 0), 17818c2ecf20Sopenharmony_ci STM32_TIM(TIM3_K, "tim3_k", "ck1_tim", RCC_APB1ENSETR, 1), 17828c2ecf20Sopenharmony_ci STM32_TIM(TIM4_K, "tim4_k", "ck1_tim", RCC_APB1ENSETR, 2), 17838c2ecf20Sopenharmony_ci STM32_TIM(TIM5_K, "tim5_k", "ck1_tim", RCC_APB1ENSETR, 3), 17848c2ecf20Sopenharmony_ci STM32_TIM(TIM6_K, "tim6_k", "ck1_tim", RCC_APB1ENSETR, 4), 17858c2ecf20Sopenharmony_ci STM32_TIM(TIM7_K, "tim7_k", "ck1_tim", RCC_APB1ENSETR, 5), 17868c2ecf20Sopenharmony_ci STM32_TIM(TIM12_K, "tim12_k", "ck1_tim", RCC_APB1ENSETR, 6), 17878c2ecf20Sopenharmony_ci STM32_TIM(TIM13_K, "tim13_k", "ck1_tim", RCC_APB1ENSETR, 7), 17888c2ecf20Sopenharmony_ci STM32_TIM(TIM14_K, "tim14_k", "ck1_tim", RCC_APB1ENSETR, 8), 17898c2ecf20Sopenharmony_ci STM32_TIM(TIM1_K, "tim1_k", "ck2_tim", RCC_APB2ENSETR, 0), 17908c2ecf20Sopenharmony_ci STM32_TIM(TIM8_K, "tim8_k", "ck2_tim", RCC_APB2ENSETR, 1), 17918c2ecf20Sopenharmony_ci STM32_TIM(TIM15_K, "tim15_k", "ck2_tim", RCC_APB2ENSETR, 2), 17928c2ecf20Sopenharmony_ci STM32_TIM(TIM16_K, "tim16_k", "ck2_tim", RCC_APB2ENSETR, 3), 17938c2ecf20Sopenharmony_ci STM32_TIM(TIM17_K, "tim17_k", "ck2_tim", RCC_APB2ENSETR, 4), 17948c2ecf20Sopenharmony_ci 17958c2ecf20Sopenharmony_ci /* Peripheral clocks */ 17968c2ecf20Sopenharmony_ci PCLK(TIM2, "tim2", "pclk1", CLK_IGNORE_UNUSED, G_TIM2), 17978c2ecf20Sopenharmony_ci PCLK(TIM3, "tim3", "pclk1", CLK_IGNORE_UNUSED, G_TIM3), 17988c2ecf20Sopenharmony_ci PCLK(TIM4, "tim4", "pclk1", CLK_IGNORE_UNUSED, G_TIM4), 17998c2ecf20Sopenharmony_ci PCLK(TIM5, "tim5", "pclk1", CLK_IGNORE_UNUSED, G_TIM5), 18008c2ecf20Sopenharmony_ci PCLK(TIM6, "tim6", "pclk1", CLK_IGNORE_UNUSED, G_TIM6), 18018c2ecf20Sopenharmony_ci PCLK(TIM7, "tim7", "pclk1", CLK_IGNORE_UNUSED, G_TIM7), 18028c2ecf20Sopenharmony_ci PCLK(TIM12, "tim12", "pclk1", CLK_IGNORE_UNUSED, G_TIM12), 18038c2ecf20Sopenharmony_ci PCLK(TIM13, "tim13", "pclk1", CLK_IGNORE_UNUSED, G_TIM13), 18048c2ecf20Sopenharmony_ci PCLK(TIM14, "tim14", "pclk1", CLK_IGNORE_UNUSED, G_TIM14), 18058c2ecf20Sopenharmony_ci PCLK(LPTIM1, "lptim1", "pclk1", 0, G_LPTIM1), 18068c2ecf20Sopenharmony_ci PCLK(SPI2, "spi2", "pclk1", 0, G_SPI2), 18078c2ecf20Sopenharmony_ci PCLK(SPI3, "spi3", "pclk1", 0, G_SPI3), 18088c2ecf20Sopenharmony_ci PCLK(USART2, "usart2", "pclk1", 0, G_USART2), 18098c2ecf20Sopenharmony_ci PCLK(USART3, "usart3", "pclk1", 0, G_USART3), 18108c2ecf20Sopenharmony_ci PCLK(UART4, "uart4", "pclk1", 0, G_UART4), 18118c2ecf20Sopenharmony_ci PCLK(UART5, "uart5", "pclk1", 0, G_UART5), 18128c2ecf20Sopenharmony_ci PCLK(UART7, "uart7", "pclk1", 0, G_UART7), 18138c2ecf20Sopenharmony_ci PCLK(UART8, "uart8", "pclk1", 0, G_UART8), 18148c2ecf20Sopenharmony_ci PCLK(I2C1, "i2c1", "pclk1", 0, G_I2C1), 18158c2ecf20Sopenharmony_ci PCLK(I2C2, "i2c2", "pclk1", 0, G_I2C2), 18168c2ecf20Sopenharmony_ci PCLK(I2C3, "i2c3", "pclk1", 0, G_I2C3), 18178c2ecf20Sopenharmony_ci PCLK(I2C5, "i2c5", "pclk1", 0, G_I2C5), 18188c2ecf20Sopenharmony_ci PCLK(SPDIF, "spdif", "pclk1", 0, G_SPDIF), 18198c2ecf20Sopenharmony_ci PCLK(CEC, "cec", "pclk1", 0, G_CEC), 18208c2ecf20Sopenharmony_ci PCLK(DAC12, "dac12", "pclk1", 0, G_DAC12), 18218c2ecf20Sopenharmony_ci PCLK(MDIO, "mdio", "pclk1", 0, G_MDIO), 18228c2ecf20Sopenharmony_ci PCLK(TIM1, "tim1", "pclk2", CLK_IGNORE_UNUSED, G_TIM1), 18238c2ecf20Sopenharmony_ci PCLK(TIM8, "tim8", "pclk2", CLK_IGNORE_UNUSED, G_TIM8), 18248c2ecf20Sopenharmony_ci PCLK(TIM15, "tim15", "pclk2", CLK_IGNORE_UNUSED, G_TIM15), 18258c2ecf20Sopenharmony_ci PCLK(TIM16, "tim16", "pclk2", CLK_IGNORE_UNUSED, G_TIM16), 18268c2ecf20Sopenharmony_ci PCLK(TIM17, "tim17", "pclk2", CLK_IGNORE_UNUSED, G_TIM17), 18278c2ecf20Sopenharmony_ci PCLK(SPI1, "spi1", "pclk2", 0, G_SPI1), 18288c2ecf20Sopenharmony_ci PCLK(SPI4, "spi4", "pclk2", 0, G_SPI4), 18298c2ecf20Sopenharmony_ci PCLK(SPI5, "spi5", "pclk2", 0, G_SPI5), 18308c2ecf20Sopenharmony_ci PCLK(USART6, "usart6", "pclk2", 0, G_USART6), 18318c2ecf20Sopenharmony_ci PCLK(SAI1, "sai1", "pclk2", 0, G_SAI1), 18328c2ecf20Sopenharmony_ci PCLK(SAI2, "sai2", "pclk2", 0, G_SAI2), 18338c2ecf20Sopenharmony_ci PCLK(SAI3, "sai3", "pclk2", 0, G_SAI3), 18348c2ecf20Sopenharmony_ci PCLK(DFSDM, "dfsdm", "pclk2", 0, G_DFSDM), 18358c2ecf20Sopenharmony_ci PCLK(FDCAN, "fdcan", "pclk2", 0, G_FDCAN), 18368c2ecf20Sopenharmony_ci PCLK(LPTIM2, "lptim2", "pclk3", 0, G_LPTIM2), 18378c2ecf20Sopenharmony_ci PCLK(LPTIM3, "lptim3", "pclk3", 0, G_LPTIM3), 18388c2ecf20Sopenharmony_ci PCLK(LPTIM4, "lptim4", "pclk3", 0, G_LPTIM4), 18398c2ecf20Sopenharmony_ci PCLK(LPTIM5, "lptim5", "pclk3", 0, G_LPTIM5), 18408c2ecf20Sopenharmony_ci PCLK(SAI4, "sai4", "pclk3", 0, G_SAI4), 18418c2ecf20Sopenharmony_ci PCLK(SYSCFG, "syscfg", "pclk3", 0, G_SYSCFG), 18428c2ecf20Sopenharmony_ci PCLK(VREF, "vref", "pclk3", 13, G_VREF), 18438c2ecf20Sopenharmony_ci PCLK(TMPSENS, "tmpsens", "pclk3", 0, G_TMPSENS), 18448c2ecf20Sopenharmony_ci PCLK(PMBCTRL, "pmbctrl", "pclk3", 0, G_PMBCTRL), 18458c2ecf20Sopenharmony_ci PCLK(HDP, "hdp", "pclk3", 0, G_HDP), 18468c2ecf20Sopenharmony_ci PCLK(LTDC, "ltdc", "pclk4", 0, G_LTDC), 18478c2ecf20Sopenharmony_ci PCLK(DSI, "dsi", "pclk4", 0, G_DSI), 18488c2ecf20Sopenharmony_ci PCLK(IWDG2, "iwdg2", "pclk4", 0, G_IWDG2), 18498c2ecf20Sopenharmony_ci PCLK(USBPHY, "usbphy", "pclk4", 0, G_USBPHY), 18508c2ecf20Sopenharmony_ci PCLK(STGENRO, "stgenro", "pclk4", 0, G_STGENRO), 18518c2ecf20Sopenharmony_ci PCLK(SPI6, "spi6", "pclk5", 0, G_SPI6), 18528c2ecf20Sopenharmony_ci PCLK(I2C4, "i2c4", "pclk5", 0, G_I2C4), 18538c2ecf20Sopenharmony_ci PCLK(I2C6, "i2c6", "pclk5", 0, G_I2C6), 18548c2ecf20Sopenharmony_ci PCLK(USART1, "usart1", "pclk5", 0, G_USART1), 18558c2ecf20Sopenharmony_ci PCLK(RTCAPB, "rtcapb", "pclk5", CLK_IGNORE_UNUSED | 18568c2ecf20Sopenharmony_ci CLK_IS_CRITICAL, G_RTCAPB), 18578c2ecf20Sopenharmony_ci PCLK(TZC1, "tzc1", "ck_axi", CLK_IGNORE_UNUSED, G_TZC1), 18588c2ecf20Sopenharmony_ci PCLK(TZC2, "tzc2", "ck_axi", CLK_IGNORE_UNUSED, G_TZC2), 18598c2ecf20Sopenharmony_ci PCLK(TZPC, "tzpc", "pclk5", CLK_IGNORE_UNUSED, G_TZPC), 18608c2ecf20Sopenharmony_ci PCLK(IWDG1, "iwdg1", "pclk5", 0, G_IWDG1), 18618c2ecf20Sopenharmony_ci PCLK(BSEC, "bsec", "pclk5", CLK_IGNORE_UNUSED, G_BSEC), 18628c2ecf20Sopenharmony_ci PCLK(STGEN, "stgen", "pclk5", CLK_IGNORE_UNUSED, G_STGEN), 18638c2ecf20Sopenharmony_ci PCLK(DMA1, "dma1", "ck_mcu", 0, G_DMA1), 18648c2ecf20Sopenharmony_ci PCLK(DMA2, "dma2", "ck_mcu", 0, G_DMA2), 18658c2ecf20Sopenharmony_ci PCLK(DMAMUX, "dmamux", "ck_mcu", 0, G_DMAMUX), 18668c2ecf20Sopenharmony_ci PCLK(ADC12, "adc12", "ck_mcu", 0, G_ADC12), 18678c2ecf20Sopenharmony_ci PCLK(USBO, "usbo", "ck_mcu", 0, G_USBO), 18688c2ecf20Sopenharmony_ci PCLK(SDMMC3, "sdmmc3", "ck_mcu", 0, G_SDMMC3), 18698c2ecf20Sopenharmony_ci PCLK(DCMI, "dcmi", "ck_mcu", 0, G_DCMI), 18708c2ecf20Sopenharmony_ci PCLK(CRYP2, "cryp2", "ck_mcu", 0, G_CRYP2), 18718c2ecf20Sopenharmony_ci PCLK(HASH2, "hash2", "ck_mcu", 0, G_HASH2), 18728c2ecf20Sopenharmony_ci PCLK(RNG2, "rng2", "ck_mcu", 0, G_RNG2), 18738c2ecf20Sopenharmony_ci PCLK(CRC2, "crc2", "ck_mcu", 0, G_CRC2), 18748c2ecf20Sopenharmony_ci PCLK(HSEM, "hsem", "ck_mcu", 0, G_HSEM), 18758c2ecf20Sopenharmony_ci PCLK(IPCC, "ipcc", "ck_mcu", 0, G_IPCC), 18768c2ecf20Sopenharmony_ci PCLK(GPIOA, "gpioa", "ck_mcu", 0, G_GPIOA), 18778c2ecf20Sopenharmony_ci PCLK(GPIOB, "gpiob", "ck_mcu", 0, G_GPIOB), 18788c2ecf20Sopenharmony_ci PCLK(GPIOC, "gpioc", "ck_mcu", 0, G_GPIOC), 18798c2ecf20Sopenharmony_ci PCLK(GPIOD, "gpiod", "ck_mcu", 0, G_GPIOD), 18808c2ecf20Sopenharmony_ci PCLK(GPIOE, "gpioe", "ck_mcu", 0, G_GPIOE), 18818c2ecf20Sopenharmony_ci PCLK(GPIOF, "gpiof", "ck_mcu", 0, G_GPIOF), 18828c2ecf20Sopenharmony_ci PCLK(GPIOG, "gpiog", "ck_mcu", 0, G_GPIOG), 18838c2ecf20Sopenharmony_ci PCLK(GPIOH, "gpioh", "ck_mcu", 0, G_GPIOH), 18848c2ecf20Sopenharmony_ci PCLK(GPIOI, "gpioi", "ck_mcu", 0, G_GPIOI), 18858c2ecf20Sopenharmony_ci PCLK(GPIOJ, "gpioj", "ck_mcu", 0, G_GPIOJ), 18868c2ecf20Sopenharmony_ci PCLK(GPIOK, "gpiok", "ck_mcu", 0, G_GPIOK), 18878c2ecf20Sopenharmony_ci PCLK(GPIOZ, "gpioz", "ck_axi", CLK_IGNORE_UNUSED, G_GPIOZ), 18888c2ecf20Sopenharmony_ci PCLK(CRYP1, "cryp1", "ck_axi", CLK_IGNORE_UNUSED, G_CRYP1), 18898c2ecf20Sopenharmony_ci PCLK(HASH1, "hash1", "ck_axi", CLK_IGNORE_UNUSED, G_HASH1), 18908c2ecf20Sopenharmony_ci PCLK(RNG1, "rng1", "ck_axi", 0, G_RNG1), 18918c2ecf20Sopenharmony_ci PCLK(BKPSRAM, "bkpsram", "ck_axi", CLK_IGNORE_UNUSED, G_BKPSRAM), 18928c2ecf20Sopenharmony_ci PCLK(MDMA, "mdma", "ck_axi", 0, G_MDMA), 18938c2ecf20Sopenharmony_ci PCLK(GPU, "gpu", "ck_axi", 0, G_GPU), 18948c2ecf20Sopenharmony_ci PCLK(ETHTX, "ethtx", "ck_axi", 0, G_ETHTX), 18958c2ecf20Sopenharmony_ci PCLK(ETHRX, "ethrx", "ck_axi", 0, G_ETHRX), 18968c2ecf20Sopenharmony_ci PCLK(ETHMAC, "ethmac", "ck_axi", 0, G_ETHMAC), 18978c2ecf20Sopenharmony_ci PCLK(FMC, "fmc", "ck_axi", CLK_IGNORE_UNUSED, G_FMC), 18988c2ecf20Sopenharmony_ci PCLK(QSPI, "qspi", "ck_axi", CLK_IGNORE_UNUSED, G_QSPI), 18998c2ecf20Sopenharmony_ci PCLK(SDMMC1, "sdmmc1", "ck_axi", 0, G_SDMMC1), 19008c2ecf20Sopenharmony_ci PCLK(SDMMC2, "sdmmc2", "ck_axi", 0, G_SDMMC2), 19018c2ecf20Sopenharmony_ci PCLK(CRC1, "crc1", "ck_axi", 0, G_CRC1), 19028c2ecf20Sopenharmony_ci PCLK(USBH, "usbh", "ck_axi", 0, G_USBH), 19038c2ecf20Sopenharmony_ci PCLK(ETHSTP, "ethstp", "ck_axi", 0, G_ETHSTP), 19048c2ecf20Sopenharmony_ci PCLK(DDRPERFM, "ddrperfm", "pclk4", 0, G_DDRPERFM), 19058c2ecf20Sopenharmony_ci 19068c2ecf20Sopenharmony_ci /* Kernel clocks */ 19078c2ecf20Sopenharmony_ci KCLK(SDMMC1_K, "sdmmc1_k", sdmmc12_src, 0, G_SDMMC1, M_SDMMC12), 19088c2ecf20Sopenharmony_ci KCLK(SDMMC2_K, "sdmmc2_k", sdmmc12_src, 0, G_SDMMC2, M_SDMMC12), 19098c2ecf20Sopenharmony_ci KCLK(SDMMC3_K, "sdmmc3_k", sdmmc3_src, 0, G_SDMMC3, M_SDMMC3), 19108c2ecf20Sopenharmony_ci KCLK(FMC_K, "fmc_k", fmc_src, 0, G_FMC, M_FMC), 19118c2ecf20Sopenharmony_ci KCLK(QSPI_K, "qspi_k", qspi_src, 0, G_QSPI, M_QSPI), 19128c2ecf20Sopenharmony_ci KCLK(RNG1_K, "rng1_k", rng_src, 0, G_RNG1, M_RNG1), 19138c2ecf20Sopenharmony_ci KCLK(RNG2_K, "rng2_k", rng_src, 0, G_RNG2, M_RNG2), 19148c2ecf20Sopenharmony_ci KCLK(USBPHY_K, "usbphy_k", usbphy_src, 0, G_USBPHY, M_USBPHY), 19158c2ecf20Sopenharmony_ci KCLK(STGEN_K, "stgen_k", stgen_src, CLK_IS_CRITICAL, G_STGEN, M_STGEN), 19168c2ecf20Sopenharmony_ci KCLK(SPDIF_K, "spdif_k", spdif_src, 0, G_SPDIF, M_SPDIF), 19178c2ecf20Sopenharmony_ci KCLK(SPI1_K, "spi1_k", spi123_src, 0, G_SPI1, M_SPI1), 19188c2ecf20Sopenharmony_ci KCLK(SPI2_K, "spi2_k", spi123_src, 0, G_SPI2, M_SPI23), 19198c2ecf20Sopenharmony_ci KCLK(SPI3_K, "spi3_k", spi123_src, 0, G_SPI3, M_SPI23), 19208c2ecf20Sopenharmony_ci KCLK(SPI4_K, "spi4_k", spi45_src, 0, G_SPI4, M_SPI45), 19218c2ecf20Sopenharmony_ci KCLK(SPI5_K, "spi5_k", spi45_src, 0, G_SPI5, M_SPI45), 19228c2ecf20Sopenharmony_ci KCLK(SPI6_K, "spi6_k", spi6_src, 0, G_SPI6, M_SPI6), 19238c2ecf20Sopenharmony_ci KCLK(CEC_K, "cec_k", cec_src, 0, G_CEC, M_CEC), 19248c2ecf20Sopenharmony_ci KCLK(I2C1_K, "i2c1_k", i2c12_src, 0, G_I2C1, M_I2C12), 19258c2ecf20Sopenharmony_ci KCLK(I2C2_K, "i2c2_k", i2c12_src, 0, G_I2C2, M_I2C12), 19268c2ecf20Sopenharmony_ci KCLK(I2C3_K, "i2c3_k", i2c35_src, 0, G_I2C3, M_I2C35), 19278c2ecf20Sopenharmony_ci KCLK(I2C5_K, "i2c5_k", i2c35_src, 0, G_I2C5, M_I2C35), 19288c2ecf20Sopenharmony_ci KCLK(I2C4_K, "i2c4_k", i2c46_src, 0, G_I2C4, M_I2C46), 19298c2ecf20Sopenharmony_ci KCLK(I2C6_K, "i2c6_k", i2c46_src, 0, G_I2C6, M_I2C46), 19308c2ecf20Sopenharmony_ci KCLK(LPTIM1_K, "lptim1_k", lptim1_src, 0, G_LPTIM1, M_LPTIM1), 19318c2ecf20Sopenharmony_ci KCLK(LPTIM2_K, "lptim2_k", lptim23_src, 0, G_LPTIM2, M_LPTIM23), 19328c2ecf20Sopenharmony_ci KCLK(LPTIM3_K, "lptim3_k", lptim23_src, 0, G_LPTIM3, M_LPTIM23), 19338c2ecf20Sopenharmony_ci KCLK(LPTIM4_K, "lptim4_k", lptim45_src, 0, G_LPTIM4, M_LPTIM45), 19348c2ecf20Sopenharmony_ci KCLK(LPTIM5_K, "lptim5_k", lptim45_src, 0, G_LPTIM5, M_LPTIM45), 19358c2ecf20Sopenharmony_ci KCLK(USART1_K, "usart1_k", usart1_src, 0, G_USART1, M_USART1), 19368c2ecf20Sopenharmony_ci KCLK(USART2_K, "usart2_k", usart234578_src, 0, G_USART2, M_UART24), 19378c2ecf20Sopenharmony_ci KCLK(USART3_K, "usart3_k", usart234578_src, 0, G_USART3, M_UART35), 19388c2ecf20Sopenharmony_ci KCLK(UART4_K, "uart4_k", usart234578_src, 0, G_UART4, M_UART24), 19398c2ecf20Sopenharmony_ci KCLK(UART5_K, "uart5_k", usart234578_src, 0, G_UART5, M_UART35), 19408c2ecf20Sopenharmony_ci KCLK(USART6_K, "uart6_k", usart6_src, 0, G_USART6, M_USART6), 19418c2ecf20Sopenharmony_ci KCLK(UART7_K, "uart7_k", usart234578_src, 0, G_UART7, M_UART78), 19428c2ecf20Sopenharmony_ci KCLK(UART8_K, "uart8_k", usart234578_src, 0, G_UART8, M_UART78), 19438c2ecf20Sopenharmony_ci KCLK(FDCAN_K, "fdcan_k", fdcan_src, 0, G_FDCAN, M_FDCAN), 19448c2ecf20Sopenharmony_ci KCLK(SAI1_K, "sai1_k", sai_src, 0, G_SAI1, M_SAI1), 19458c2ecf20Sopenharmony_ci KCLK(SAI2_K, "sai2_k", sai2_src, 0, G_SAI2, M_SAI2), 19468c2ecf20Sopenharmony_ci KCLK(SAI3_K, "sai3_k", sai_src, 0, G_SAI3, M_SAI3), 19478c2ecf20Sopenharmony_ci KCLK(SAI4_K, "sai4_k", sai_src, 0, G_SAI4, M_SAI4), 19488c2ecf20Sopenharmony_ci KCLK(ADC12_K, "adc12_k", adc12_src, 0, G_ADC12, M_ADC12), 19498c2ecf20Sopenharmony_ci KCLK(DSI_K, "dsi_k", dsi_src, 0, G_DSI, M_DSI), 19508c2ecf20Sopenharmony_ci KCLK(ADFSDM_K, "adfsdm_k", sai_src, 0, G_ADFSDM, M_SAI1), 19518c2ecf20Sopenharmony_ci KCLK(USBO_K, "usbo_k", usbo_src, 0, G_USBO, M_USBO), 19528c2ecf20Sopenharmony_ci KCLK(ETHCK_K, "ethck_k", eth_src, 0, G_ETHCK, M_ETHCK), 19538c2ecf20Sopenharmony_ci 19548c2ecf20Sopenharmony_ci /* Particulary Kernel Clocks (no mux or no gate) */ 19558c2ecf20Sopenharmony_ci MGATE_MP1(DFSDM_K, "dfsdm_k", "ck_mcu", 0, G_DFSDM), 19568c2ecf20Sopenharmony_ci MGATE_MP1(DSI_PX, "dsi_px", "pll4_q", CLK_SET_RATE_PARENT, G_DSI), 19578c2ecf20Sopenharmony_ci MGATE_MP1(LTDC_PX, "ltdc_px", "pll4_q", CLK_SET_RATE_PARENT, G_LTDC), 19588c2ecf20Sopenharmony_ci MGATE_MP1(GPU_K, "gpu_k", "pll2_q", 0, G_GPU), 19598c2ecf20Sopenharmony_ci MGATE_MP1(DAC12_K, "dac12_k", "ck_lsi", 0, G_DAC12), 19608c2ecf20Sopenharmony_ci 19618c2ecf20Sopenharmony_ci COMPOSITE(ETHPTP_K, "ethptp_k", eth_src, CLK_OPS_PARENT_ENABLE | 19628c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, 19638c2ecf20Sopenharmony_ci _NO_GATE, 19648c2ecf20Sopenharmony_ci _MMUX(M_ETHCK), 19658c2ecf20Sopenharmony_ci _DIV(RCC_ETHCKSELR, 4, 4, 0, NULL)), 19668c2ecf20Sopenharmony_ci 19678c2ecf20Sopenharmony_ci /* RTC clock */ 19688c2ecf20Sopenharmony_ci DIV(NO_ID, "ck_hse_rtc", "ck_hse", 0, RCC_RTCDIVR, 0, 6, 0), 19698c2ecf20Sopenharmony_ci 19708c2ecf20Sopenharmony_ci COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE | 19718c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 19728c2ecf20Sopenharmony_ci _GATE(RCC_BDCR, 20, 0), 19738c2ecf20Sopenharmony_ci _MUX(RCC_BDCR, 16, 2, 0), 19748c2ecf20Sopenharmony_ci _NO_DIV), 19758c2ecf20Sopenharmony_ci 19768c2ecf20Sopenharmony_ci /* MCO clocks */ 19778c2ecf20Sopenharmony_ci COMPOSITE(CK_MCO1, "ck_mco1", mco1_src, CLK_OPS_PARENT_ENABLE | 19788c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, 19798c2ecf20Sopenharmony_ci _GATE(RCC_MCO1CFGR, 12, 0), 19808c2ecf20Sopenharmony_ci _MUX(RCC_MCO1CFGR, 0, 3, 0), 19818c2ecf20Sopenharmony_ci _DIV(RCC_MCO1CFGR, 4, 4, 0, NULL)), 19828c2ecf20Sopenharmony_ci 19838c2ecf20Sopenharmony_ci COMPOSITE(CK_MCO2, "ck_mco2", mco2_src, CLK_OPS_PARENT_ENABLE | 19848c2ecf20Sopenharmony_ci CLK_SET_RATE_NO_REPARENT, 19858c2ecf20Sopenharmony_ci _GATE(RCC_MCO2CFGR, 12, 0), 19868c2ecf20Sopenharmony_ci _MUX(RCC_MCO2CFGR, 0, 3, 0), 19878c2ecf20Sopenharmony_ci _DIV(RCC_MCO2CFGR, 4, 4, 0, NULL)), 19888c2ecf20Sopenharmony_ci 19898c2ecf20Sopenharmony_ci /* Debug clocks */ 19908c2ecf20Sopenharmony_ci GATE(CK_DBG, "ck_sys_dbg", "ck_axi", CLK_IGNORE_UNUSED, 19918c2ecf20Sopenharmony_ci RCC_DBGCFGR, 8, 0), 19928c2ecf20Sopenharmony_ci 19938c2ecf20Sopenharmony_ci COMPOSITE(CK_TRACE, "ck_trace", ck_trace_src, CLK_OPS_PARENT_ENABLE, 19948c2ecf20Sopenharmony_ci _GATE(RCC_DBGCFGR, 9, 0), 19958c2ecf20Sopenharmony_ci _NO_MUX, 19968c2ecf20Sopenharmony_ci _DIV(RCC_DBGCFGR, 0, 3, 0, ck_trace_div_table)), 19978c2ecf20Sopenharmony_ci}; 19988c2ecf20Sopenharmony_ci 19998c2ecf20Sopenharmony_cistruct stm32_clock_match_data { 20008c2ecf20Sopenharmony_ci const struct clock_config *cfg; 20018c2ecf20Sopenharmony_ci unsigned int num; 20028c2ecf20Sopenharmony_ci unsigned int maxbinding; 20038c2ecf20Sopenharmony_ci}; 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_cistatic struct stm32_clock_match_data stm32mp1_data = { 20068c2ecf20Sopenharmony_ci .cfg = stm32mp1_clock_cfg, 20078c2ecf20Sopenharmony_ci .num = ARRAY_SIZE(stm32mp1_clock_cfg), 20088c2ecf20Sopenharmony_ci .maxbinding = STM32MP1_LAST_CLK, 20098c2ecf20Sopenharmony_ci}; 20108c2ecf20Sopenharmony_ci 20118c2ecf20Sopenharmony_cistatic const struct of_device_id stm32mp1_match_data[] = { 20128c2ecf20Sopenharmony_ci { 20138c2ecf20Sopenharmony_ci .compatible = "st,stm32mp1-rcc", 20148c2ecf20Sopenharmony_ci .data = &stm32mp1_data, 20158c2ecf20Sopenharmony_ci }, 20168c2ecf20Sopenharmony_ci { } 20178c2ecf20Sopenharmony_ci}; 20188c2ecf20Sopenharmony_ci 20198c2ecf20Sopenharmony_cistatic int stm32_register_hw_clk(struct device *dev, 20208c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data, 20218c2ecf20Sopenharmony_ci void __iomem *base, spinlock_t *lock, 20228c2ecf20Sopenharmony_ci const struct clock_config *cfg) 20238c2ecf20Sopenharmony_ci{ 20248c2ecf20Sopenharmony_ci struct clk_hw **hws; 20258c2ecf20Sopenharmony_ci struct clk_hw *hw = ERR_PTR(-ENOENT); 20268c2ecf20Sopenharmony_ci 20278c2ecf20Sopenharmony_ci hws = clk_data->hws; 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_ci if (cfg->func) 20308c2ecf20Sopenharmony_ci hw = (*cfg->func)(dev, clk_data, base, lock, cfg); 20318c2ecf20Sopenharmony_ci 20328c2ecf20Sopenharmony_ci if (IS_ERR(hw)) { 20338c2ecf20Sopenharmony_ci pr_err("Unable to register %s\n", cfg->name); 20348c2ecf20Sopenharmony_ci return PTR_ERR(hw); 20358c2ecf20Sopenharmony_ci } 20368c2ecf20Sopenharmony_ci 20378c2ecf20Sopenharmony_ci if (cfg->id != NO_ID) 20388c2ecf20Sopenharmony_ci hws[cfg->id] = hw; 20398c2ecf20Sopenharmony_ci 20408c2ecf20Sopenharmony_ci return 0; 20418c2ecf20Sopenharmony_ci} 20428c2ecf20Sopenharmony_ci 20438c2ecf20Sopenharmony_cistatic int stm32_rcc_init(struct device_node *np, 20448c2ecf20Sopenharmony_ci void __iomem *base, 20458c2ecf20Sopenharmony_ci const struct of_device_id *match_data) 20468c2ecf20Sopenharmony_ci{ 20478c2ecf20Sopenharmony_ci struct clk_hw_onecell_data *clk_data; 20488c2ecf20Sopenharmony_ci struct clk_hw **hws; 20498c2ecf20Sopenharmony_ci const struct of_device_id *match; 20508c2ecf20Sopenharmony_ci const struct stm32_clock_match_data *data; 20518c2ecf20Sopenharmony_ci int err, n, max_binding; 20528c2ecf20Sopenharmony_ci 20538c2ecf20Sopenharmony_ci match = of_match_node(match_data, np); 20548c2ecf20Sopenharmony_ci if (!match) { 20558c2ecf20Sopenharmony_ci pr_err("%s: match data not found\n", __func__); 20568c2ecf20Sopenharmony_ci return -ENODEV; 20578c2ecf20Sopenharmony_ci } 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_ci data = match->data; 20608c2ecf20Sopenharmony_ci 20618c2ecf20Sopenharmony_ci max_binding = data->maxbinding; 20628c2ecf20Sopenharmony_ci 20638c2ecf20Sopenharmony_ci clk_data = kzalloc(struct_size(clk_data, hws, max_binding), 20648c2ecf20Sopenharmony_ci GFP_KERNEL); 20658c2ecf20Sopenharmony_ci if (!clk_data) 20668c2ecf20Sopenharmony_ci return -ENOMEM; 20678c2ecf20Sopenharmony_ci 20688c2ecf20Sopenharmony_ci clk_data->num = max_binding; 20698c2ecf20Sopenharmony_ci 20708c2ecf20Sopenharmony_ci hws = clk_data->hws; 20718c2ecf20Sopenharmony_ci 20728c2ecf20Sopenharmony_ci for (n = 0; n < max_binding; n++) 20738c2ecf20Sopenharmony_ci hws[n] = ERR_PTR(-ENOENT); 20748c2ecf20Sopenharmony_ci 20758c2ecf20Sopenharmony_ci for (n = 0; n < data->num; n++) { 20768c2ecf20Sopenharmony_ci err = stm32_register_hw_clk(NULL, clk_data, base, &rlock, 20778c2ecf20Sopenharmony_ci &data->cfg[n]); 20788c2ecf20Sopenharmony_ci if (err) { 20798c2ecf20Sopenharmony_ci pr_err("%s: can't register %s\n", __func__, 20808c2ecf20Sopenharmony_ci data->cfg[n].name); 20818c2ecf20Sopenharmony_ci 20828c2ecf20Sopenharmony_ci kfree(clk_data); 20838c2ecf20Sopenharmony_ci 20848c2ecf20Sopenharmony_ci return err; 20858c2ecf20Sopenharmony_ci } 20868c2ecf20Sopenharmony_ci } 20878c2ecf20Sopenharmony_ci 20888c2ecf20Sopenharmony_ci return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data); 20898c2ecf20Sopenharmony_ci} 20908c2ecf20Sopenharmony_ci 20918c2ecf20Sopenharmony_cistatic void stm32mp1_rcc_init(struct device_node *np) 20928c2ecf20Sopenharmony_ci{ 20938c2ecf20Sopenharmony_ci void __iomem *base; 20948c2ecf20Sopenharmony_ci 20958c2ecf20Sopenharmony_ci base = of_iomap(np, 0); 20968c2ecf20Sopenharmony_ci if (!base) { 20978c2ecf20Sopenharmony_ci pr_err("%pOFn: unable to map resource", np); 20988c2ecf20Sopenharmony_ci of_node_put(np); 20998c2ecf20Sopenharmony_ci return; 21008c2ecf20Sopenharmony_ci } 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_ci if (stm32_rcc_init(np, base, stm32mp1_match_data)) { 21038c2ecf20Sopenharmony_ci iounmap(base); 21048c2ecf20Sopenharmony_ci of_node_put(np); 21058c2ecf20Sopenharmony_ci } 21068c2ecf20Sopenharmony_ci} 21078c2ecf20Sopenharmony_ci 21088c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(stm32mp1_rcc, "st,stm32mp1-rcc", stm32mp1_rcc_init); 2109