1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP2+ common Clock Management (CM) IP block functions
5 * Copyright (C) 2012 Texas Instruments, Inc.
8 * XXX This code should eventually be moved to a CM driver.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/errno.h>
14 #include <linux/bug.h>
16 #include <linux/of_address.h>
25 * cm_ll_data: function pointers to SoC-specific implementations of
28 static struct cm_ll_data null_cm_ll_data
;
29 static const struct cm_ll_data
*cm_ll_data
= &null_cm_ll_data
;
31 /* cm_base: base virtual address of the CM IP block */
32 struct omap_domain_base cm_base
;
34 /* cm2_base: base virtual address of the CM2 IP block (OMAP44xx only) */
35 struct omap_domain_base cm2_base
;
37 #define CM_NO_CLOCKS 0x1
38 #define CM_SINGLE_INSTANCE 0x2
41 * omap2_set_globals_cm - set the CM/CM2 base addresses (for early use)
42 * @cm: CM base virtual address
43 * @cm2: CM2 base virtual address (if present on the booted SoC)
45 * XXX Will be replaced when the PRM/CM drivers are completed.
47 void __init
omap2_set_globals_cm(void __iomem
*cm
, void __iomem
*cm2
)
54 * cm_split_idlest_reg - split CM_IDLEST reg addr into its components
55 * @idlest_reg: CM_IDLEST* virtual address
56 * @prcm_inst: pointer to an s16 to return the PRCM instance offset
57 * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
59 * Given an absolute CM_IDLEST register address @idlest_reg, passes
60 * the PRCM instance offset and IDLEST register ID back to the caller
61 * via the @prcm_inst and @idlest_reg_id. Returns -EINVAL upon error,
62 * or 0 upon success. XXX This function is only needed until absolute
63 * register addresses are removed from the OMAP struct clk records.
65 int cm_split_idlest_reg(struct clk_omap_reg
*idlest_reg
, s16
*prcm_inst
,
69 if (!cm_ll_data
->split_idlest_reg
) {
70 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
75 ret
= cm_ll_data
->split_idlest_reg(idlest_reg
, prcm_inst
,
77 *prcm_inst
-= cm_base
.offset
;
82 * omap_cm_wait_module_ready - wait for a module to leave idle or standby
83 * @part: PRCM partition
84 * @prcm_mod: PRCM module offset
85 * @idlest_reg: CM_IDLESTx register
86 * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
88 * Wait for the PRCM to indicate that the module identified by
89 * (@prcm_mod, @idlest_id, @idlest_shift) is clocked. Return 0 upon
90 * success, -EBUSY if the module doesn't enable in time, or -EINVAL if
91 * no per-SoC wait_module_ready() function pointer has been registered
92 * or if the idlest register is unknown on the SoC.
94 int omap_cm_wait_module_ready(u8 part
, s16 prcm_mod
, u16 idlest_reg
,
97 if (!cm_ll_data
->wait_module_ready
) {
98 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
103 return cm_ll_data
->wait_module_ready(part
, prcm_mod
, idlest_reg
,
108 * omap_cm_wait_module_idle - wait for a module to enter idle or standby
109 * @part: PRCM partition
110 * @prcm_mod: PRCM module offset
111 * @idlest_reg: CM_IDLESTx register
112 * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
114 * Wait for the PRCM to indicate that the module identified by
115 * (@prcm_mod, @idlest_id, @idlest_shift) is no longer clocked. Return
116 * 0 upon success, -EBUSY if the module doesn't enable in time, or
117 * -EINVAL if no per-SoC wait_module_idle() function pointer has been
118 * registered or if the idlest register is unknown on the SoC.
120 int omap_cm_wait_module_idle(u8 part
, s16 prcm_mod
, u16 idlest_reg
,
123 if (!cm_ll_data
->wait_module_idle
) {
124 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
129 return cm_ll_data
->wait_module_idle(part
, prcm_mod
, idlest_reg
,
134 * omap_cm_module_enable - enable a module
135 * @mode: target mode for the module
136 * @part: PRCM partition
137 * @inst: PRCM instance
138 * @clkctrl_offs: CM_CLKCTRL register offset for the module
140 * Enables clocks for a module identified by (@part, @inst, @clkctrl_offs)
141 * making its IO space accessible. Return 0 upon success, -EINVAL if no
142 * per-SoC module_enable() function pointer has been registered.
144 int omap_cm_module_enable(u8 mode
, u8 part
, u16 inst
, u16 clkctrl_offs
)
146 if (!cm_ll_data
->module_enable
) {
147 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
152 cm_ll_data
->module_enable(mode
, part
, inst
, clkctrl_offs
);
157 * omap_cm_module_disable - disable a module
158 * @part: PRCM partition
159 * @inst: PRCM instance
160 * @clkctrl_offs: CM_CLKCTRL register offset for the module
162 * Disables clocks for a module identified by (@part, @inst, @clkctrl_offs)
163 * makings its IO space inaccessible. Return 0 upon success, -EINVAL if
164 * no per-SoC module_disable() function pointer has been registered.
166 int omap_cm_module_disable(u8 part
, u16 inst
, u16 clkctrl_offs
)
168 if (!cm_ll_data
->module_disable
) {
169 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
174 cm_ll_data
->module_disable(part
, inst
, clkctrl_offs
);
178 u32
omap_cm_xlate_clkctrl(u8 part
, u16 inst
, u16 clkctrl_offs
)
180 if (!cm_ll_data
->xlate_clkctrl
) {
181 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
185 return cm_ll_data
->xlate_clkctrl(part
, inst
, clkctrl_offs
);
189 * cm_register - register per-SoC low-level data with the CM
190 * @cld: low-level per-SoC OMAP CM data & function pointers to register
192 * Register per-SoC low-level OMAP CM data and function pointers with
193 * the OMAP CM common interface. The caller must keep the data
194 * pointed to by @cld valid until it calls cm_unregister() and
195 * it returns successfully. Returns 0 upon success, -EINVAL if @cld
196 * is NULL, or -EEXIST if cm_register() has already been called
197 * without an intervening cm_unregister().
199 int cm_register(const struct cm_ll_data
*cld
)
204 if (cm_ll_data
!= &null_cm_ll_data
)
213 * cm_unregister - unregister per-SoC low-level data & function pointers
214 * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
216 * Unregister per-SoC low-level OMAP CM data and function pointers
217 * that were previously registered with cm_register(). The
218 * caller may not destroy any of the data pointed to by @cld until
219 * this function returns successfully. Returns 0 upon success, or
220 * -EINVAL if @cld is NULL or if @cld does not match the struct
221 * cm_ll_data * previously registered by cm_register().
223 int cm_unregister(const struct cm_ll_data
*cld
)
225 if (!cld
|| cm_ll_data
!= cld
)
228 cm_ll_data
= &null_cm_ll_data
;
233 #if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
234 defined(CONFIG_SOC_DRA7XX)
235 static struct omap_prcm_init_data cm_data __initdata
= {
237 .init
= omap4_cm_init
,
240 static struct omap_prcm_init_data cm2_data __initdata
= {
241 .index
= TI_CLKM_CM2
,
242 .init
= omap4_cm_init
,
246 #ifdef CONFIG_ARCH_OMAP2
247 static struct omap_prcm_init_data omap2_prcm_data __initdata
= {
249 .init
= omap2xxx_cm_init
,
250 .flags
= CM_NO_CLOCKS
| CM_SINGLE_INSTANCE
,
254 #ifdef CONFIG_ARCH_OMAP3
255 static struct omap_prcm_init_data omap3_cm_data __initdata
= {
257 .init
= omap3xxx_cm_init
,
258 .flags
= CM_SINGLE_INSTANCE
,
261 * IVA2 offset is a negative value, must offset the cm_base address
262 * by this to get it to positive side on the iomap
264 .offset
= -OMAP3430_IVA2_MOD
,
268 #if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
269 static struct omap_prcm_init_data am3_prcm_data __initdata
= {
271 .flags
= CM_NO_CLOCKS
| CM_SINGLE_INSTANCE
,
272 .init
= am33xx_cm_init
,
276 #ifdef CONFIG_SOC_AM43XX
277 static struct omap_prcm_init_data am4_prcm_data __initdata
= {
279 .flags
= CM_NO_CLOCKS
| CM_SINGLE_INSTANCE
,
280 .init
= omap4_cm_init
,
284 static const struct of_device_id omap_cm_dt_match_table
[] __initconst
= {
285 #ifdef CONFIG_ARCH_OMAP2
286 { .compatible
= "ti,omap2-prcm", .data
= &omap2_prcm_data
},
288 #ifdef CONFIG_ARCH_OMAP3
289 { .compatible
= "ti,omap3-cm", .data
= &omap3_cm_data
},
291 #ifdef CONFIG_ARCH_OMAP4
292 { .compatible
= "ti,omap4-cm1", .data
= &cm_data
},
293 { .compatible
= "ti,omap4-cm2", .data
= &cm2_data
},
295 #ifdef CONFIG_SOC_OMAP5
296 { .compatible
= "ti,omap5-cm-core-aon", .data
= &cm_data
},
297 { .compatible
= "ti,omap5-cm-core", .data
= &cm2_data
},
299 #ifdef CONFIG_SOC_DRA7XX
300 { .compatible
= "ti,dra7-cm-core-aon", .data
= &cm_data
},
301 { .compatible
= "ti,dra7-cm-core", .data
= &cm2_data
},
303 #ifdef CONFIG_SOC_AM33XX
304 { .compatible
= "ti,am3-prcm", .data
= &am3_prcm_data
},
306 #ifdef CONFIG_SOC_AM43XX
307 { .compatible
= "ti,am4-prcm", .data
= &am4_prcm_data
},
309 #ifdef CONFIG_SOC_TI81XX
310 { .compatible
= "ti,dm814-prcm", .data
= &am3_prcm_data
},
311 { .compatible
= "ti,dm816-prcm", .data
= &am3_prcm_data
},
317 * omap2_cm_base_init - initialize iomappings for the CM drivers
319 * Detects and initializes the iomappings for the CM driver, based
320 * on the DT data. Returns 0 in success, negative error value
323 int __init
omap2_cm_base_init(void)
325 struct device_node
*np
;
326 const struct of_device_id
*match
;
327 struct omap_prcm_init_data
*data
;
330 struct omap_domain_base
*mem
= NULL
;
332 for_each_matching_node_and_match(np
, omap_cm_dt_match_table
, &match
) {
333 data
= (struct omap_prcm_init_data
*)match
->data
;
335 ret
= of_address_to_resource(np
, 0, &res
);
339 if (data
->index
== TI_CLKM_CM
)
342 if (data
->index
== TI_CLKM_CM2
)
345 data
->mem
= ioremap(res
.start
, resource_size(&res
));
348 mem
->pa
= res
.start
+ data
->offset
;
349 mem
->va
= data
->mem
+ data
->offset
;
350 mem
->offset
= data
->offset
;
355 if (data
->init
&& (data
->flags
& CM_SINGLE_INSTANCE
||
356 (cm_base
.va
&& cm2_base
.va
)))
364 * omap_cm_init - low level init for the CM drivers
366 * Initializes the low level clock infrastructure for CM drivers.
367 * Returns 0 in success, negative error value in failure.
369 int __init
omap_cm_init(void)
371 struct device_node
*np
;
372 const struct of_device_id
*match
;
373 const struct omap_prcm_init_data
*data
;
376 for_each_matching_node_and_match(np
, omap_cm_dt_match_table
, &match
) {
379 if (data
->flags
& CM_NO_CLOCKS
)
382 ret
= omap2_clk_provider_init(np
, data
->index
, NULL
, data
->mem
);