1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/clk-provider.h>
7 #include <linux/slab.h>
8 #include <linux/spinlock.h>
12 #define CCDR_MMDC_CH0_MASK BIT(17)
13 #define CCDR_MMDC_CH1_MASK BIT(16)
15 DEFINE_SPINLOCK(imx_ccm_lock
);
17 void imx_unregister_clocks(struct clk
*clks
[], unsigned int count
)
21 for (i
= 0; i
< count
; i
++)
22 clk_unregister(clks
[i
]);
25 void __init
imx_mmdc_mask_handshake(void __iomem
*ccm_base
,
30 reg
= readl_relaxed(ccm_base
+ CCM_CCDR
);
31 reg
|= chn
== 0 ? CCDR_MMDC_CH0_MASK
: CCDR_MMDC_CH1_MASK
;
32 writel_relaxed(reg
, ccm_base
+ CCM_CCDR
);
35 void imx_check_clocks(struct clk
*clks
[], unsigned int count
)
39 for (i
= 0; i
< count
; i
++)
41 pr_err("i.MX clk %u: register failed with %ld\n",
45 void imx_check_clk_hws(struct clk_hw
*clks
[], unsigned int count
)
49 for (i
= 0; i
< count
; i
++)
51 pr_err("i.MX clk %u: register failed with %ld\n",
55 static struct clk
* __init
imx_obtain_fixed_clock_from_dt(const char *name
)
57 struct of_phandle_args phandle
;
58 struct clk
*clk
= ERR_PTR(-ENODEV
);
61 path
= kasprintf(GFP_KERNEL
, "/clocks/%s", name
);
63 return ERR_PTR(-ENOMEM
);
65 phandle
.np
= of_find_node_by_path(path
);
69 clk
= of_clk_get_from_provider(&phandle
);
70 of_node_put(phandle
.np
);
75 struct clk
* __init
imx_obtain_fixed_clock(
76 const char *name
, unsigned long rate
)
80 clk
= imx_obtain_fixed_clock_from_dt(name
);
82 clk
= imx_clk_fixed(name
, rate
);
86 struct clk_hw
* __init
imx_obtain_fixed_clock_hw(
87 const char *name
, unsigned long rate
)
91 clk
= imx_obtain_fixed_clock_from_dt(name
);
93 clk
= imx_clk_fixed(name
, rate
);
94 return __clk_get_hw(clk
);
97 struct clk_hw
* __init
imx_obtain_fixed_clk_hw(struct device_node
*np
,
102 clk
= of_clk_get_by_name(np
, name
);
104 return ERR_PTR(-ENOENT
);
106 return __clk_get_hw(clk
);
110 * This fixups the register CCM_CSCMR1 write value.
111 * The write/read/divider values of the aclk_podf field
112 * of that register have the relationship described by
113 * the following table:
115 * write value read value divider
123 * 3b'111 3b'001 2(default)
125 * That's why we do the xor operation below.
127 #define CSCMR1_FIXUP 0x00600000
129 void imx_cscmr1_fixup(u32
*val
)
131 *val
^= CSCMR1_FIXUP
;
135 static int imx_keep_uart_clocks
;
136 static struct clk
** const *imx_uart_clocks
;
138 static int __init
imx_keep_uart_clocks_param(char *str
)
140 imx_keep_uart_clocks
= 1;
144 __setup_param("earlycon", imx_keep_uart_earlycon
,
145 imx_keep_uart_clocks_param
, 0);
146 __setup_param("earlyprintk", imx_keep_uart_earlyprintk
,
147 imx_keep_uart_clocks_param
, 0);
149 void imx_register_uart_clocks(struct clk
** const clks
[])
151 if (imx_keep_uart_clocks
) {
154 imx_uart_clocks
= clks
;
155 for (i
= 0; imx_uart_clocks
[i
]; i
++)
156 clk_prepare_enable(*imx_uart_clocks
[i
]);
160 static int __init
imx_clk_disable_uart(void)
162 if (imx_keep_uart_clocks
&& imx_uart_clocks
) {
165 for (i
= 0; imx_uart_clocks
[i
]; i
++)
166 clk_disable_unprepare(*imx_uart_clocks
[i
]);
171 late_initcall_sync(imx_clk_disable_uart
);