]> git.sur5r.net Git - u-boot/commitdiff
mx25: Add function to set PER clocks
authorBenoît Thébaudeau <benoit@wsystem.com>
Wed, 3 May 2017 09:59:05 +0000 (11:59 +0200)
committerStefano Babic <sbabic@denx.de>
Wed, 31 May 2017 08:14:30 +0000 (10:14 +0200)
Introduce the imx_set_perclk() function to make it possible to set the
PER clocks.

Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>
arch/arm/cpu/arm926ejs/mx25/generic.c
arch/arm/include/asm/arch-mx25/clock.h

index f02cffb95e44084e6ef1b8b60c2400c4fd8a5c58..5d9bc6c0f1773960b8f293d2d00e485375067c91 100644 (file)
@@ -113,6 +113,25 @@ static ulong imx_get_perclk(int clk)
        return fref / div;
 }
 
+int imx_set_perclk(enum mxc_clock clk, bool from_upll, unsigned int freq)
+{
+       struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
+       ulong fref = from_upll ? imx_get_upllclk() : imx_get_ahbclk();
+       ulong div = (fref + freq - 1) / freq;
+
+       if (clk > MXC_UART_CLK || !div || --div > CCM_PERCLK_MASK)
+               return -EINVAL;
+
+       clrsetbits_le32(&ccm->pcdr[CCM_PERCLK_REG(clk)],
+                       CCM_PERCLK_MASK << CCM_PERCLK_SHIFT(clk),
+                       div << CCM_PERCLK_SHIFT(clk));
+       if (from_upll)
+               setbits_le32(&ccm->mcr, 1 << clk);
+       else
+               clrbits_le32(&ccm->mcr, 1 << clk);
+       return 0;
+}
+
 unsigned int mxc_get_clock(enum mxc_clock clk)
 {
        if (clk >= MXC_CLK_NUM)
index 9fdaa9dc07024392debc16f2cdff42114f7cb927..7753cafa9f488a2f8e97845407d129550dbb859e 100644 (file)
@@ -51,6 +51,7 @@ enum mxc_clock {
        MXC_CLK_NUM
 };
 
+int imx_set_perclk(enum mxc_clock clk, bool from_upll, unsigned int freq);
 unsigned int mxc_get_clock(enum mxc_clock clk);
 
 #define imx_get_uartclk()      mxc_get_clock(MXC_UART_CLK)