1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/clk-provider.h>
6 #include <linux/slab.h>
7 #include <linux/spinlock.h>
10 DEFINE_SPINLOCK(imx_ccm_lock);
12 void __init imx_check_clocks(struct clk *clks[], unsigned int count)
16 for (i = 0; i < count; i++)
18 pr_err("i.MX clk %u: register failed with %ld\n",
22 void imx_check_clk_hws(struct clk_hw *clks[], unsigned int count)
26 for (i = 0; i < count; i++)
28 pr_err("i.MX clk %u: register failed with %ld\n",
32 static struct clk * __init imx_obtain_fixed_clock_from_dt(const char *name)
34 struct of_phandle_args phandle;
35 struct clk *clk = ERR_PTR(-ENODEV);
38 path = kasprintf(GFP_KERNEL, "/clocks/%s", name);
40 return ERR_PTR(-ENOMEM);
42 phandle.np = of_find_node_by_path(path);
46 clk = of_clk_get_from_provider(&phandle);
47 of_node_put(phandle.np);
52 struct clk * __init imx_obtain_fixed_clock(
53 const char *name, unsigned long rate)
57 clk = imx_obtain_fixed_clock_from_dt(name);
59 clk = imx_clk_fixed(name, rate);
63 struct clk_hw * __init imx_obtain_fixed_clk_hw(struct device_node *np,
68 clk = of_clk_get_by_name(np, name);
70 return ERR_PTR(-ENOENT);
72 return __clk_get_hw(clk);
76 * This fixups the register CCM_CSCMR1 write value.
77 * The write/read/divider values of the aclk_podf field
78 * of that register have the relationship described by
79 * the following table:
81 * write value read value divider
89 * 3b'111 3b'001 2(default)
91 * That's why we do the xor operation below.
93 #define CSCMR1_FIXUP 0x00600000
95 void imx_cscmr1_fixup(u32 *val)
101 static int imx_keep_uart_clocks __initdata;
102 static struct clk ** const *imx_uart_clocks __initdata;
104 static int __init imx_keep_uart_clocks_param(char *str)
106 imx_keep_uart_clocks = 1;
110 __setup_param("earlycon", imx_keep_uart_earlycon,
111 imx_keep_uart_clocks_param, 0);
112 __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
113 imx_keep_uart_clocks_param, 0);
115 void __init imx_register_uart_clocks(struct clk ** const clks[])
117 if (imx_keep_uart_clocks) {
120 imx_uart_clocks = clks;
121 for (i = 0; imx_uart_clocks[i]; i++)
122 clk_prepare_enable(*imx_uart_clocks[i]);
126 static int __init imx_clk_disable_uart(void)
128 if (imx_keep_uart_clocks && imx_uart_clocks) {
131 for (i = 0; imx_uart_clocks[i]; i++)
132 clk_disable_unprepare(*imx_uart_clocks[i]);
137 late_initcall_sync(imx_clk_disable_uart);