clk: stm32mp1: Add RTC clock entry
[oweals/u-boot.git] / drivers / clk / clk_stm32mp1.c
index 1a77eba39cbb430a99fcad34b6768dcccfe4bf96..5806d48696f45061b600c5e648f3468953d2d946 100644 (file)
 #include <dt-bindings/clock/stm32mp1-clks.h>
 #include <dt-bindings/clock/stm32mp1-clksrc.h>
 
+#ifndef CONFIG_STM32MP1_TRUSTED
 #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
 /* activate clock tree initialization in the driver */
 #define STM32MP1_CLOCK_TREE_INIT
 #endif
+#endif
 
 #define MAX_HSI_HZ             64000000
 
@@ -88,6 +90,7 @@
 #define RCC_PLL4CSGR           0x8A4
 #define RCC_I2C12CKSELR                0x8C0
 #define RCC_I2C35CKSELR                0x8C4
+#define RCC_SPI2S1CKSELR       0x8D8
 #define RCC_UART6CKSELR                0x8E4
 #define RCC_UART24CKSELR       0x8E8
 #define RCC_UART35CKSELR       0x8EC
 #define RCC_QSPICKSELR         0x900
 #define RCC_FMCCKSELR          0x904
 #define RCC_USBCKSELR          0x91C
+#define RCC_DSICKSELR          0x924
+#define RCC_ADCCKSELR          0x928
 #define RCC_MP_APB1ENSETR      0xA00
 #define RCC_MP_APB2ENSETR      0XA08
 #define RCC_MP_APB3ENSETR      0xA10
 #define RCC_MP_AHB2ENSETR      0xA18
+#define RCC_MP_AHB3ENSETR      0xA20
 #define RCC_MP_AHB4ENSETR      0xA28
 
 /* used for most of SELR register */
 #define RCC_BDCR_LSEON         BIT(0)
 #define RCC_BDCR_LSEBYP                BIT(1)
 #define RCC_BDCR_LSERDY                BIT(2)
+#define RCC_BDCR_DIGBYP                BIT(3)
 #define RCC_BDCR_LSEDRV_MASK   GENMASK(5, 4)
 #define RCC_BDCR_LSEDRV_SHIFT  4
 #define RCC_BDCR_LSECSSON      BIT(8)
 /* used for ALL PLLNCR registers */
 #define RCC_PLLNCR_PLLON       BIT(0)
 #define RCC_PLLNCR_PLLRDY      BIT(1)
+#define RCC_PLLNCR_SSCG_CTRL   BIT(2)
 #define RCC_PLLNCR_DIVPEN      BIT(4)
 #define RCC_PLLNCR_DIVQEN      BIT(5)
 #define RCC_PLLNCR_DIVREN      BIT(6)
 #define RCC_PLLNCFGR1_IFRGE_SHIFT      24
 #define RCC_PLLNCFGR1_IFRGE_MASK       GENMASK(25, 24)
 
-/* used for ALL PLLNCFGR2 registers */
+/* used for ALL PLLNCFGR2 registers , using stm32mp1_div_id */
+#define RCC_PLLNCFGR2_SHIFT(div_id)    ((div_id) * 8)
 #define RCC_PLLNCFGR2_DIVX_MASK                GENMASK(6, 0)
-#define RCC_PLLNCFGR2_DIVP_SHIFT       0
+#define RCC_PLLNCFGR2_DIVP_SHIFT       RCC_PLLNCFGR2_SHIFT(_DIV_P)
 #define RCC_PLLNCFGR2_DIVP_MASK                GENMASK(6, 0)
-#define RCC_PLLNCFGR2_DIVQ_SHIFT       8
+#define RCC_PLLNCFGR2_DIVQ_SHIFT       RCC_PLLNCFGR2_SHIFT(_DIV_Q)
 #define RCC_PLLNCFGR2_DIVQ_MASK                GENMASK(14, 8)
-#define RCC_PLLNCFGR2_DIVR_SHIFT       16
+#define RCC_PLLNCFGR2_DIVR_SHIFT       RCC_PLLNCFGR2_SHIFT(_DIV_R)
 #define RCC_PLLNCFGR2_DIVR_MASK                GENMASK(22, 16)
 
 /* used for ALL PLLNFRACR registers */
 /* used for RCC_OCENSETR and RCC_OCENCLRR registers */
 #define RCC_OCENR_HSION                        BIT(0)
 #define RCC_OCENR_CSION                        BIT(4)
+#define RCC_OCENR_DIGBYP               BIT(7)
 #define RCC_OCENR_HSEON                        BIT(8)
 #define RCC_OCENR_HSEBYP               BIT(10)
 #define RCC_OCENR_HSECSSON             BIT(11)
@@ -235,7 +245,6 @@ enum stm32mp1_parent_id {
        _LSI,
        _LSE,
        _I2S_CKIN,
-       _USB_PHY_48,
        NB_OSC,
 
 /* other parent source */
@@ -266,6 +275,8 @@ enum stm32mp1_parent_id {
        _CK_PER,
        _CK_MPU,
        _CK_MCU,
+       _DSI_PHY,
+       _USB_PHY_48,
        _PARENT_NB,
        _UNKNOWN_ID = 0xff,
 };
@@ -286,6 +297,10 @@ enum stm32mp1_parent_sel {
        _USBPHY_SEL,
        _USBO_SEL,
        _STGEN_SEL,
+       _DSI_SEL,
+       _ADC12_SEL,
+       _SPI1_SEL,
+       _RTC_SEL,
        _PARENT_SEL_NB,
        _UNKNOWN_SEL = 0xff,
 };
@@ -507,20 +522,30 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
        STM32MP1_CLK_SET_CLR(RCC_MP_APB1ENSETR, 23, I2C3_K, _I2C35_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB1ENSETR, 24, I2C5_K, _I2C35_SEL),
 
+       STM32MP1_CLK_SET_CLR(RCC_MP_APB2ENSETR, 8, SPI1_K, _SPI1_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB2ENSETR, 13, USART6_K, _UART6_SEL),
 
        STM32MP1_CLK_SET_CLR_F(RCC_MP_APB3ENSETR, 13, VREF, _PCLK3),
 
+       STM32MP1_CLK_SET_CLR_F(RCC_MP_APB4ENSETR, 0, LTDC_PX, _PLL4_Q),
+       STM32MP1_CLK_SET_CLR_F(RCC_MP_APB4ENSETR, 4, DSI_PX, _PLL4_Q),
+       STM32MP1_CLK_SET_CLR(RCC_MP_APB4ENSETR, 4, DSI_K, _DSI_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB4ENSETR, 8, DDRPERFM, _UNKNOWN_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB4ENSETR, 15, IWDG2, _UNKNOWN_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB4ENSETR, 16, USBPHY_K, _USBPHY_SEL),
 
        STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 2, I2C4_K, _I2C46_SEL),
+       STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 8, RTCAPB, _PCLK5),
        STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 20, STGEN_K, _STGEN_SEL),
 
+       STM32MP1_CLK_SET_CLR_F(RCC_MP_AHB2ENSETR, 5, ADC12, _HCLK2),
+       STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 5, ADC12_K, _ADC12_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 8, USBO_K, _USBO_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB2ENSETR, 16, SDMMC3_K, _SDMMC3_SEL),
 
+       STM32MP1_CLK_SET_CLR(RCC_MP_AHB3ENSETR, 11, HSEM, _UNKNOWN_SEL),
+       STM32MP1_CLK_SET_CLR(RCC_MP_AHB3ENSETR, 12, IPCC, _UNKNOWN_SEL),
+
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 0, GPIOA, _UNKNOWN_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 1, GPIOB, _UNKNOWN_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB4ENSETR, 2, GPIOC, _UNKNOWN_SEL),
@@ -535,10 +560,9 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
 
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB5ENSETR, 0, GPIOZ, _UNKNOWN_SEL),
 
-       STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 7, ETHCK, _UNKNOWN_SEL),
+       STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 7, ETHCK_K, _ETH_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 8, ETHTX, _UNKNOWN_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 9, ETHRX, _UNKNOWN_SEL),
-       STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 10, ETHMAC_K, _ETH_SEL),
        STM32MP1_CLK_SET_CLR_F(RCC_MP_AHB6ENSETR, 10, ETHMAC, _ACLK),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 12, FMC_K, _FMC_SEL),
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 14, QSPI_K, _QSPI_SEL),
@@ -547,6 +571,8 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
        STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 24, USBH, _UNKNOWN_SEL),
 
        STM32MP1_CLK(RCC_DBGCFGR, 8, CK_DBG, _UNKNOWN_SEL),
+
+       STM32MP1_CLK(RCC_BDCR, 20, RTC, _RTC_SEL),
 };
 
 static const u8 i2c12_parents[] = {_PCLK1, _PLL4_R, _HSI_KER, _CSI_KER};
@@ -568,6 +594,11 @@ static const u8 fmc_parents[] = {_ACLK, _PLL3_R, _PLL4_P, _CK_PER};
 static const u8 usbphy_parents[] = {_HSE_KER, _PLL4_R, _HSE_KER_DIV2};
 static const u8 usbo_parents[] = {_PLL4_R, _USB_PHY_48};
 static const u8 stgen_parents[] = {_HSI_KER, _HSE_KER};
+static const u8 dsi_parents[] = {_DSI_PHY, _PLL4_P};
+static const u8 adc_parents[] = {_PLL4_R, _CK_PER, _PLL3_Q};
+static const u8 spi_parents[] = {_PLL4_P, _PLL3_Q, _I2S_CKIN, _CK_PER,
+                                _PLL3_R};
+static const u8 rtc_parents[] = {_UNKNOWN_ID, _LSE, _LSI, _HSE};
 
 static const struct stm32mp1_clk_sel stm32mp1_clk_sel[_PARENT_SEL_NB] = {
        STM32MP1_CLK_PARENT(_I2C12_SEL, RCC_I2C12CKSELR, 0, 0x7, i2c12_parents),
@@ -590,6 +621,12 @@ static const struct stm32mp1_clk_sel stm32mp1_clk_sel[_PARENT_SEL_NB] = {
        STM32MP1_CLK_PARENT(_USBPHY_SEL, RCC_USBCKSELR, 0, 0x3, usbphy_parents),
        STM32MP1_CLK_PARENT(_USBO_SEL, RCC_USBCKSELR, 4, 0x1, usbo_parents),
        STM32MP1_CLK_PARENT(_STGEN_SEL, RCC_STGENCKSELR, 0, 0x3, stgen_parents),
+       STM32MP1_CLK_PARENT(_DSI_SEL, RCC_DSICKSELR, 0, 0x1, dsi_parents),
+       STM32MP1_CLK_PARENT(_ADC12_SEL, RCC_ADCCKSELR, 0, 0x1, adc_parents),
+       STM32MP1_CLK_PARENT(_SPI1_SEL, RCC_SPI2S1CKSELR, 0, 0x7, spi_parents),
+       STM32MP1_CLK_PARENT(_RTC_SEL, RCC_BDCR, RCC_BDCR_RTCSRC_SHIFT,
+                           (RCC_BDCR_RTCSRC_MASK >> RCC_BDCR_RTCSRC_SHIFT),
+                           rtc_parents),
 };
 
 #ifdef STM32MP1_CLOCK_TREE_INIT
@@ -646,8 +683,8 @@ static const u8 stm32mp1_axi_div[8] = {
        1, 2, 3, 4, 4, 4, 4, 4
 };
 
-#ifdef DEBUG
-static const char * const stm32mp1_clk_parent_name[_PARENT_NB] = {
+static const __maybe_unused
+char * const stm32mp1_clk_parent_name[_PARENT_NB] = {
        [_HSI] = "HSI",
        [_HSE] = "HSE",
        [_CSI] = "CSI",
@@ -681,10 +718,12 @@ static const char * const stm32mp1_clk_parent_name[_PARENT_NB] = {
        [_CK_PER] = "CK_PER",
        [_CK_MPU] = "CK_MPU",
        [_CK_MCU] = "CK_MCU",
-       [_USB_PHY_48] = "USB_PHY_48"
+       [_USB_PHY_48] = "USB_PHY_48",
+       [_DSI_PHY] = "DSI_PHY_PLL",
 };
 
-static const char * const stm32mp1_clk_parent_sel_name[_PARENT_SEL_NB] = {
+static const __maybe_unused
+char * const stm32mp1_clk_parent_sel_name[_PARENT_SEL_NB] = {
        [_I2C12_SEL] = "I2C12",
        [_I2C35_SEL] = "I2C35",
        [_I2C46_SEL] = "I2C46",
@@ -699,9 +738,12 @@ static const char * const stm32mp1_clk_parent_sel_name[_PARENT_SEL_NB] = {
        [_FMC_SEL] = "FMC",
        [_USBPHY_SEL] = "USBPHY",
        [_USBO_SEL] = "USBO",
-       [_STGEN_SEL] = "STGEN"
+       [_STGEN_SEL] = "STGEN",
+       [_DSI_SEL] = "DSI",
+       [_ADC12_SEL] = "ADC12",
+       [_SPI1_SEL] = "SPI1",
+       [_RTC_SEL] = "RTC",
 };
-#endif
 
 static const struct stm32mp1_clk_data stm32mp1_data = {
        .gate = stm32mp1_clk_gate,
@@ -772,10 +814,11 @@ static int stm32mp1_clk_get_parent(struct stm32mp1_clk_priv *priv,
        const struct stm32mp1_clk_sel *sel = priv->data->sel;
        int i;
        int s, p;
+       unsigned int idx;
 
-       for (i = 0; i < ARRAY_SIZE(stm32mp1_clks); i++)
-               if (stm32mp1_clks[i][0] == id)
-                       return stm32mp1_clks[i][1];
+       for (idx = 0; idx < ARRAY_SIZE(stm32mp1_clks); idx++)
+               if (stm32mp1_clks[idx][0] == id)
+                       return stm32mp1_clks[idx][1];
 
        i = stm32mp1_clk_get_id(priv, id);
        if (i < 0)
@@ -807,60 +850,87 @@ static int stm32mp1_clk_get_parent(struct stm32mp1_clk_priv *priv,
        return -EINVAL;
 }
 
-static ulong stm32mp1_read_pll_freq(struct stm32mp1_clk_priv *priv,
-                                   int pll_id, int div_id)
+static ulong  pll_get_fref_ck(struct stm32mp1_clk_priv *priv,
+                             int pll_id)
 {
        const struct stm32mp1_clk_pll *pll = priv->data->pll;
-       int divm, divn, divy, src;
-       ulong refclk, dfout;
-       u32 selr, cfgr1, cfgr2, fracr;
-       const u8 shift[_DIV_NB] = {
-               [_DIV_P] = RCC_PLLNCFGR2_DIVP_SHIFT,
-               [_DIV_Q] = RCC_PLLNCFGR2_DIVQ_SHIFT,
-               [_DIV_R] = RCC_PLLNCFGR2_DIVR_SHIFT };
-
-       debug("%s(%d, %d)\n", __func__, pll_id, div_id);
-       if (div_id > _DIV_NB)
-               return 0;
+       u32 selr;
+       int src;
+       ulong refclk;
 
+       /* Get current refclk */
        selr = readl(priv->base + pll[pll_id].rckxselr);
+       src = selr & RCC_SELR_SRC_MASK;
+
+       refclk = stm32mp1_clk_get_fixed(priv, pll[pll_id].refclk[src]);
+       debug("PLL%d : selr=%x refclk = %d kHz\n",
+             pll_id, selr, (u32)(refclk / 1000));
+
+       return refclk;
+}
+
+/*
+ * pll_get_fvco() : return the VCO or (VCO / 2) frequency for the requested PLL
+ * - PLL1 & PLL2 => return VCO / 2 with Fpll_y_ck = FVCO / 2 * (DIVy + 1)
+ * - PLL3 & PLL4 => return VCO     with Fpll_y_ck = FVCO / (DIVy + 1)
+ * => in all the case Fpll_y_ck = pll_get_fvco() / (DIVy + 1)
+ */
+static ulong pll_get_fvco(struct stm32mp1_clk_priv *priv,
+                         int pll_id)
+{
+       const struct stm32mp1_clk_pll *pll = priv->data->pll;
+       int divm, divn;
+       ulong refclk, fvco;
+       u32 cfgr1, fracr;
+
        cfgr1 = readl(priv->base + pll[pll_id].pllxcfgr1);
-       cfgr2 = readl(priv->base + pll[pll_id].pllxcfgr2);
        fracr = readl(priv->base + pll[pll_id].pllxfracr);
 
-       debug("PLL%d : selr=%x cfgr1=%x cfgr2=%x fracr=%x\n",
-             pll_id, selr, cfgr1, cfgr2, fracr);
-
        divm = (cfgr1 & (RCC_PLLNCFGR1_DIVM_MASK)) >> RCC_PLLNCFGR1_DIVM_SHIFT;
        divn = cfgr1 & RCC_PLLNCFGR1_DIVN_MASK;
-       divy = (cfgr2 >> shift[div_id]) & RCC_PLLNCFGR2_DIVX_MASK;
 
-       debug("        DIVN=%d DIVM=%d DIVY=%d\n", divn, divm, divy);
+       debug("PLL%d : cfgr1=%x fracr=%x DIVN=%d DIVM=%d\n",
+             pll_id, cfgr1, fracr, divn, divm);
 
-       src = selr & RCC_SELR_SRC_MASK;
-       refclk = stm32mp1_clk_get_fixed(priv, pll[pll_id].refclk[src]);
-
-       debug("        refclk = %d kHz\n", (u32)(refclk / 1000));
+       refclk = pll_get_fref_ck(priv, pll_id);
 
-       /*
-        * For: PLL1 & PLL2 => VCO is * 2 but ck_pll_y is also / 2
-        * So same final result than PLL2 et 4
-        * with FRACV :
-        *   Fck_pll_y = Fck_ref * ((DIVN + 1) + FRACV / 2^13)
-        *               / (DIVM + 1) * (DIVy + 1)
+       /* with FRACV :
+        *   Fvco = Fck_ref * ((DIVN + 1) + FRACV / 2^13) / (DIVM + 1)
         * without FRACV
-        *   Fck_pll_y = Fck_ref * ((DIVN + 1) / (DIVM + 1) *(DIVy + 1)
+        *   Fvco = Fck_ref * ((DIVN + 1) / (DIVM + 1)
         */
        if (fracr & RCC_PLLNFRACR_FRACLE) {
                u32 fracv = (fracr & RCC_PLLNFRACR_FRACV_MASK)
                            >> RCC_PLLNFRACR_FRACV_SHIFT;
-               dfout = (ulong)lldiv((unsigned long long)refclk *
+               fvco = (ulong)lldiv((unsigned long long)refclk *
                                     (((divn + 1) << 13) + fracv),
-                                    ((unsigned long long)(divm + 1) *
-                                     (divy + 1)) << 13);
+                                    ((unsigned long long)(divm + 1)) << 13);
        } else {
-               dfout = (ulong)(refclk * (divn + 1) / (divm + 1) * (divy + 1));
+               fvco = (ulong)(refclk * (divn + 1) / (divm + 1));
        }
+       debug("PLL%d : %s = %ld\n", pll_id, __func__, fvco);
+
+       return fvco;
+}
+
+static ulong stm32mp1_read_pll_freq(struct stm32mp1_clk_priv *priv,
+                                   int pll_id, int div_id)
+{
+       const struct stm32mp1_clk_pll *pll = priv->data->pll;
+       int divy;
+       ulong dfout;
+       u32 cfgr2;
+
+       debug("%s(%d, %d)\n", __func__, pll_id, div_id);
+       if (div_id >= _DIV_NB)
+               return 0;
+
+       cfgr2 = readl(priv->base + pll[pll_id].pllxcfgr2);
+       divy = (cfgr2 >> RCC_PLLNCFGR2_SHIFT(div_id)) & RCC_PLLNCFGR2_DIVX_MASK;
+
+       debug("PLL%d : cfgr2=%x DIVY=%d\n", pll_id, cfgr2, divy);
+
+       dfout = pll_get_fvco(priv, pll_id) / (divy + 1);
        debug("        => dfout = %d kHz\n", (u32)(dfout / 1000));
 
        return dfout;
@@ -1030,9 +1100,24 @@ static ulong stm32mp1_clk_get(struct stm32mp1_clk_priv *priv, int p)
                break;
        /* other */
        case _USB_PHY_48:
-               clock = stm32mp1_clk_get_fixed(priv, _USB_PHY_48);
+               clock = 48000000;
                break;
-
+       case _DSI_PHY:
+       {
+               struct clk clk;
+               struct udevice *dev = NULL;
+
+               if (!uclass_get_device_by_name(UCLASS_CLK, "ck_dsi_phy",
+                                              &dev)) {
+                       if (clk_request(dev, &clk)) {
+                               pr_err("ck_dsi_phy request");
+                       } else {
+                               clk.id = 0;
+                               clock = clk_get_rate(&clk);
+                       }
+               }
+               break;
+       }
        default:
                break;
        }
@@ -1115,10 +1200,7 @@ static void stm32mp1_ls_osc_set(int enable, fdt_addr_t rcc, u32 offset,
 
 static void stm32mp1_hs_ocs_set(int enable, fdt_addr_t rcc, u32 mask_on)
 {
-       if (enable)
-               setbits_le32(rcc + RCC_OCENSETR, mask_on);
-       else
-               setbits_le32(rcc + RCC_OCENCLRR, mask_on);
+       writel(mask_on, rcc + (enable ? RCC_OCENSETR : RCC_OCENCLRR));
 }
 
 static int stm32mp1_osc_wait(int enable, fdt_addr_t rcc, u32 offset,
@@ -1143,11 +1225,15 @@ static int stm32mp1_osc_wait(int enable, fdt_addr_t rcc, u32 offset,
        return ret;
 }
 
-static void stm32mp1_lse_enable(fdt_addr_t rcc, int bypass, int lsedrv)
+static void stm32mp1_lse_enable(fdt_addr_t rcc, int bypass, int digbyp,
+                               int lsedrv)
 {
        u32 value;
 
-       if (bypass)
+       if (digbyp)
+               setbits_le32(rcc + RCC_BDCR, RCC_BDCR_DIGBYP);
+
+       if (bypass || digbyp)
                setbits_le32(rcc + RCC_BDCR, RCC_BDCR_LSEBYP);
 
        /*
@@ -1182,21 +1268,23 @@ static void stm32mp1_lsi_set(fdt_addr_t rcc, int enable)
        stm32mp1_osc_wait(enable, rcc, RCC_RDLSICR, RCC_RDLSICR_LSIRDY);
 }
 
-static void stm32mp1_hse_enable(fdt_addr_t rcc, int bypass, int css)
+static void stm32mp1_hse_enable(fdt_addr_t rcc, int bypass, int digbyp, int css)
 {
-       if (bypass)
-               setbits_le32(rcc + RCC_OCENSETR, RCC_OCENR_HSEBYP);
+       if (digbyp)
+               writel(RCC_OCENR_DIGBYP, rcc + RCC_OCENSETR);
+       if (bypass || digbyp)
+               writel(RCC_OCENR_HSEBYP, rcc + RCC_OCENSETR);
 
        stm32mp1_hs_ocs_set(1, rcc, RCC_OCENR_HSEON);
        stm32mp1_osc_wait(1, rcc, RCC_OCRDYR, RCC_OCRDYR_HSERDY);
 
        if (css)
-               setbits_le32(rcc + RCC_OCENSETR, RCC_OCENR_HSECSSON);
+               writel(RCC_OCENR_HSECSSON, rcc + RCC_OCENSETR);
 }
 
 static void stm32mp1_csi_set(fdt_addr_t rcc, int enable)
 {
-       stm32mp1_ls_osc_set(enable, rcc, RCC_OCENSETR, RCC_OCENR_CSION);
+       stm32mp1_hs_ocs_set(enable, rcc, RCC_OCENR_CSION);
        stm32mp1_osc_wait(enable, rcc, RCC_OCRDYR, RCC_OCRDYR_CSIRDY);
 }
 
@@ -1251,7 +1339,10 @@ static void pll_start(struct stm32mp1_clk_priv *priv, int pll_id)
 {
        const struct stm32mp1_clk_pll *pll = priv->data->pll;
 
-       writel(RCC_PLLNCR_PLLON, priv->base + pll[pll_id].pllxcr);
+       clrsetbits_le32(priv->base + pll[pll_id].pllxcr,
+                       RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN |
+                       RCC_PLLNCR_DIVREN,
+                       RCC_PLLNCR_PLLON);
 }
 
 static int pll_output(struct stm32mp1_clk_priv *priv, int pll_id, int output)
@@ -1370,6 +1461,73 @@ static void pll_csg(struct stm32mp1_clk_priv *priv, int pll_id, u32 *csg)
                    RCC_PLLNCSGR_SSCG_MODE_MASK);
 
        writel(pllxcsg, priv->base + pll[pll_id].pllxcsgr);
+
+       setbits_le32(priv->base + pll[pll_id].pllxcr, RCC_PLLNCR_SSCG_CTRL);
+}
+
+static  __maybe_unused int pll_set_rate(struct udevice *dev,
+                                       int pll_id,
+                                       int div_id,
+                                       unsigned long clk_rate)
+{
+       struct stm32mp1_clk_priv *priv = dev_get_priv(dev);
+       unsigned int pllcfg[PLLCFG_NB];
+       ofnode plloff;
+       char name[12];
+       const struct stm32mp1_clk_pll *pll = priv->data->pll;
+       enum stm32mp1_plltype type = pll[pll_id].plltype;
+       int divm, divn, divy;
+       int ret;
+       ulong fck_ref;
+       u32 fracv;
+       u64 value;
+
+       if (div_id > _DIV_NB)
+               return -EINVAL;
+
+       sprintf(name, "st,pll@%d", pll_id);
+       plloff = dev_read_subnode(dev, name);
+       if (!ofnode_valid(plloff))
+               return -FDT_ERR_NOTFOUND;
+
+       ret = ofnode_read_u32_array(plloff, "cfg",
+                                   pllcfg, PLLCFG_NB);
+       if (ret < 0)
+               return -FDT_ERR_NOTFOUND;
+
+       fck_ref = pll_get_fref_ck(priv, pll_id);
+
+       divm = pllcfg[PLLCFG_M];
+       /* select output divider = 0: for _DIV_P, 1:_DIV_Q 2:_DIV_R */
+       divy = pllcfg[PLLCFG_P + div_id];
+
+       /* For: PLL1 & PLL2 => VCO is * 2 but ck_pll_y is also / 2
+        * So same final result than PLL2 et 4
+        * with FRACV
+        * Fck_pll_y = Fck_ref * ((DIVN + 1) + FRACV / 2^13)
+        *             / (DIVy + 1) * (DIVM + 1)
+        * value = (DIVN + 1) * 2^13 + FRACV / 2^13
+        *       = Fck_pll_y (DIVy + 1) * (DIVM + 1) * 2^13 / Fck_ref
+        */
+       value = ((u64)clk_rate * (divy + 1) * (divm + 1)) << 13;
+       value = lldiv(value, fck_ref);
+
+       divn = (value >> 13) - 1;
+       if (divn < DIVN_MIN ||
+           divn > stm32mp1_pll[type].divn_max) {
+               pr_err("divn invalid = %d", divn);
+               return -EINVAL;
+       }
+       fracv = value - ((divn + 1) << 13);
+       pllcfg[PLLCFG_N] = divn;
+
+       /* reconfigure PLL */
+       pll_stop(priv, pll_id);
+       pll_config(priv, pll_id, pllcfg, fracv);
+       pll_start(priv, pll_id);
+       pll_output(priv, pll_id, pllcfg[PLLCFG_O]);
+
+       return 0;
 }
 
 static int set_clksrc(struct stm32mp1_clk_priv *priv, unsigned int clksrc)
@@ -1394,17 +1552,21 @@ static void stgen_config(struct stm32mp1_clk_priv *priv)
        u32 stgenc, cntfid0;
        ulong rate;
 
-       stgenc = (u32)syscon_get_first_range(STM32MP_SYSCON_STGEN);
-
+       stgenc = STM32_STGEN_BASE;
        cntfid0 = readl(stgenc + STGENC_CNTFID0);
        p = stm32mp1_clk_get_parent(priv, STGEN_K);
        rate = stm32mp1_clk_get(priv, p);
 
        if (cntfid0 != rate) {
+               u64 counter;
+
                pr_debug("System Generic Counter (STGEN) update\n");
                clrbits_le32(stgenc + STGENC_CNTCR, STGENC_CNTCR_EN);
-               writel(0x0, stgenc + STGENC_CNTCVL);
-               writel(0x0, stgenc + STGENC_CNTCVU);
+               counter = (u64)readl(stgenc + STGENC_CNTCVL);
+               counter |= ((u64)(readl(stgenc + STGENC_CNTCVU))) << 32;
+               counter = lldiv(counter * (u64)rate, cntfid0);
+               writel((u32)counter, stgenc + STGENC_CNTCVL);
+               writel((u32)(counter >> 32), stgenc + STGENC_CNTCVU);
                writel(rate, stgenc + STGENC_CNTFID0);
                setbits_le32(stgenc + STGENC_CNTCR, STGENC_CNTCR_EN);
 
@@ -1547,26 +1709,27 @@ static int stm32mp1_clktree(struct udevice *dev)
                stm32mp1_lsi_set(rcc, 1);
 
        if (priv->osc[_LSE]) {
-               int bypass;
-               int lsedrv;
+               int bypass, digbyp, lsedrv;
                struct udevice *dev = priv->osc_dev[_LSE];
 
                bypass = dev_read_bool(dev, "st,bypass");
+               digbyp = dev_read_bool(dev, "st,digbypass");
                lse_css = dev_read_bool(dev, "st,css");
                lsedrv = dev_read_u32_default(dev, "st,drive",
                                              LSEDRV_MEDIUM_HIGH);
 
-               stm32mp1_lse_enable(rcc, bypass, lsedrv);
+               stm32mp1_lse_enable(rcc, bypass, digbyp, lsedrv);
        }
 
        if (priv->osc[_HSE]) {
-               int bypass, css;
+               int bypass, digbyp, css;
                struct udevice *dev = priv->osc_dev[_HSE];
 
                bypass = dev_read_bool(dev, "st,bypass");
+               digbyp = dev_read_bool(dev, "st,digbypass");
                css = dev_read_bool(dev, "st,css");
 
-               stm32mp1_hse_enable(rcc, bypass, css);
+               stm32mp1_hse_enable(rcc, bypass, digbyp, css);
        }
        /* CSI is mandatory for automatic I/O compensation (SYSCFG_CMPCR)
         * => switch on CSI even if node is not present in device tree
@@ -1695,6 +1858,88 @@ static int stm32mp1_clktree(struct udevice *dev)
 }
 #endif /* STM32MP1_CLOCK_TREE_INIT */
 
+static int pll_set_output_rate(struct udevice *dev,
+                              int pll_id,
+                              int div_id,
+                              unsigned long clk_rate)
+{
+       struct stm32mp1_clk_priv *priv = dev_get_priv(dev);
+       const struct stm32mp1_clk_pll *pll = priv->data->pll;
+       u32 pllxcr = priv->base + pll[pll_id].pllxcr;
+       int div;
+       ulong fvco;
+
+       if (div_id > _DIV_NB)
+               return -EINVAL;
+
+       fvco = pll_get_fvco(priv, pll_id);
+
+       if (fvco <= clk_rate)
+               div = 1;
+       else
+               div = DIV_ROUND_UP(fvco, clk_rate);
+
+       if (div > 128)
+               div = 128;
+
+       debug("fvco = %ld, clk_rate = %ld, div=%d\n", fvco, clk_rate, div);
+       /* stop the requested output */
+       clrbits_le32(pllxcr, 0x1 << div_id << RCC_PLLNCR_DIVEN_SHIFT);
+       /* change divider */
+       clrsetbits_le32(priv->base + pll[pll_id].pllxcfgr2,
+                       RCC_PLLNCFGR2_DIVX_MASK << RCC_PLLNCFGR2_SHIFT(div_id),
+                       (div - 1) << RCC_PLLNCFGR2_SHIFT(div_id));
+       /* start the requested output */
+       setbits_le32(pllxcr, 0x1 << div_id << RCC_PLLNCR_DIVEN_SHIFT);
+
+       return 0;
+}
+
+static ulong stm32mp1_clk_set_rate(struct clk *clk, unsigned long clk_rate)
+{
+       struct stm32mp1_clk_priv *priv = dev_get_priv(clk->dev);
+       int p;
+
+       switch (clk->id) {
+#if defined(STM32MP1_CLOCK_TREE_INIT) && \
+       defined(CONFIG_STM32MP1_DDR_INTERACTIVE)
+       case DDRPHYC:
+               break;
+#endif
+       case LTDC_PX:
+       case DSI_PX:
+               break;
+       default:
+               pr_err("not supported");
+               return -EINVAL;
+       }
+
+       p = stm32mp1_clk_get_parent(priv, clk->id);
+       if (p < 0)
+               return -EINVAL;
+
+       switch (p) {
+#if defined(STM32MP1_CLOCK_TREE_INIT) && \
+       defined(CONFIG_STM32MP1_DDR_INTERACTIVE)
+       case _PLL2_R: /* DDRPHYC */
+       {
+               /* only for change DDR clock in interactive mode */
+               ulong result;
+
+               set_clksrc(priv, CLK_AXI_HSI);
+               result = pll_set_rate(clk->dev,  _PLL2, _DIV_R, clk_rate);
+               set_clksrc(priv, CLK_AXI_PLL2P);
+               return result;
+       }
+#endif
+       case _PLL4_Q:
+               /* for LTDC_PX and DSI_PX case */
+               return pll_set_output_rate(clk->dev, _PLL4, _DIV_Q, clk_rate);
+       }
+
+       return -EINVAL;
+}
+
 static void stm32mp1_osc_clk_init(const char *name,
                                  struct stm32mp1_clk_priv *priv,
                                  int index)
@@ -1724,7 +1969,7 @@ static void stm32mp1_osc_init(struct udevice *dev)
                [_HSE] = "clk-hse",
                [_CSI] = "clk-csi",
                [_I2S_CKIN] = "i2s_ckin",
-               [_USB_PHY_48] = "ck_usbo_48m"};
+       };
 
        for (i = 0; i < NB_OSC; i++) {
                stm32mp1_osc_clk_init(name[i], priv, i);
@@ -1732,6 +1977,54 @@ static void stm32mp1_osc_init(struct udevice *dev)
        }
 }
 
+static void  __maybe_unused stm32mp1_clk_dump(struct stm32mp1_clk_priv *priv)
+{
+       char buf[32];
+       int i, s, p;
+
+       printf("Clocks:\n");
+       for (i = 0; i < _PARENT_NB; i++) {
+               printf("- %s : %s MHz\n",
+                      stm32mp1_clk_parent_name[i],
+                      strmhz(buf, stm32mp1_clk_get(priv, i)));
+       }
+       printf("Source Clocks:\n");
+       for (i = 0; i < _PARENT_SEL_NB; i++) {
+               p = (readl(priv->base + priv->data->sel[i].offset) >>
+                    priv->data->sel[i].src) & priv->data->sel[i].msk;
+               if (p < priv->data->sel[i].nb_parent) {
+                       s = priv->data->sel[i].parent[p];
+                       printf("- %s(%d) => parent %s(%d)\n",
+                              stm32mp1_clk_parent_sel_name[i], i,
+                              stm32mp1_clk_parent_name[s], s);
+               } else {
+                       printf("- %s(%d) => parent index %d is invalid\n",
+                              stm32mp1_clk_parent_sel_name[i], i, p);
+               }
+       }
+}
+
+#ifdef CONFIG_CMD_CLK
+int soc_clk_dump(void)
+{
+       struct udevice *dev;
+       struct stm32mp1_clk_priv *priv;
+       int ret;
+
+       ret = uclass_get_device_by_driver(UCLASS_CLK,
+                                         DM_GET_DRIVER(stm32mp1_clock),
+                                         &dev);
+       if (ret)
+               return ret;
+
+       priv = dev_get_priv(dev);
+
+       stm32mp1_clk_dump(priv);
+
+       return 0;
+}
+#endif
+
 static int stm32mp1_clk_probe(struct udevice *dev)
 {
        int result = 0;
@@ -1755,6 +2048,33 @@ static int stm32mp1_clk_probe(struct udevice *dev)
                result = stm32mp1_clktree(dev);
 #endif
 
+#ifndef CONFIG_SPL_BUILD
+#if defined(DEBUG)
+       /* display debug information for probe after relocation */
+       if (gd->flags & GD_FLG_RELOC)
+               stm32mp1_clk_dump(priv);
+#endif
+
+#if defined(CONFIG_DISPLAY_CPUINFO)
+       if (gd->flags & GD_FLG_RELOC) {
+               char buf[32];
+
+               printf("Clocks:\n");
+               printf("- MPU : %s MHz\n",
+                      strmhz(buf, stm32mp1_clk_get(priv, _CK_MPU)));
+               printf("- MCU : %s MHz\n",
+                      strmhz(buf, stm32mp1_clk_get(priv, _CK_MCU)));
+               printf("- AXI : %s MHz\n",
+                      strmhz(buf, stm32mp1_clk_get(priv, _ACLK)));
+               printf("- PER : %s MHz\n",
+                      strmhz(buf, stm32mp1_clk_get(priv, _CK_PER)));
+               /* DDRPHYC father */
+               printf("- DDR : %s MHz\n",
+                      strmhz(buf, stm32mp1_clk_get(priv, _PLL2_R)));
+       }
+#endif /* CONFIG_DISPLAY_CPUINFO */
+#endif
+
        return result;
 }
 
@@ -1762,17 +2082,12 @@ static const struct clk_ops stm32mp1_clk_ops = {
        .enable = stm32mp1_clk_enable,
        .disable = stm32mp1_clk_disable,
        .get_rate = stm32mp1_clk_get_rate,
-};
-
-static const struct udevice_id stm32mp1_clk_ids[] = {
-       { .compatible = "st,stm32mp1-rcc-clk" },
-       { }
+       .set_rate = stm32mp1_clk_set_rate,
 };
 
 U_BOOT_DRIVER(stm32mp1_clock) = {
        .name = "stm32mp1_clk",
        .id = UCLASS_CLK,
-       .of_match = stm32mp1_clk_ids,
        .ops = &stm32mp1_clk_ops,
        .priv_auto_alloc_size = sizeof(struct stm32mp1_clk_priv),
        .probe = stm32mp1_clk_probe,