18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OMAP2+ common Clock Management (CM) IP block functions
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments, Inc.
68c2ecf20Sopenharmony_ci * Paul Walmsley
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * XXX This code should eventually be moved to a CM driver.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/kernel.h>
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/errno.h>
148c2ecf20Sopenharmony_ci#include <linux/bug.h>
158c2ecf20Sopenharmony_ci#include <linux/of.h>
168c2ecf20Sopenharmony_ci#include <linux/of_address.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include "cm2xxx.h"
198c2ecf20Sopenharmony_ci#include "cm3xxx.h"
208c2ecf20Sopenharmony_ci#include "cm33xx.h"
218c2ecf20Sopenharmony_ci#include "cm44xx.h"
228c2ecf20Sopenharmony_ci#include "clock.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * cm_ll_data: function pointers to SoC-specific implementations of
268c2ecf20Sopenharmony_ci * common CM functions
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_cistatic struct cm_ll_data null_cm_ll_data;
298c2ecf20Sopenharmony_cistatic const struct cm_ll_data *cm_ll_data = &null_cm_ll_data;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* cm_base: base virtual address of the CM IP block */
328c2ecf20Sopenharmony_cistruct omap_domain_base cm_base;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* cm2_base: base virtual address of the CM2 IP block (OMAP44xx only) */
358c2ecf20Sopenharmony_cistruct omap_domain_base cm2_base;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define CM_NO_CLOCKS		0x1
388c2ecf20Sopenharmony_ci#define CM_SINGLE_INSTANCE	0x2
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/**
418c2ecf20Sopenharmony_ci * omap2_set_globals_cm - set the CM/CM2 base addresses (for early use)
428c2ecf20Sopenharmony_ci * @cm: CM base virtual address
438c2ecf20Sopenharmony_ci * @cm2: CM2 base virtual address (if present on the booted SoC)
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci * XXX Will be replaced when the PRM/CM drivers are completed.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_civoid __init omap2_set_globals_cm(void __iomem *cm, void __iomem *cm2)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	cm_base.va = cm;
508c2ecf20Sopenharmony_ci	cm2_base.va = cm2;
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/**
548c2ecf20Sopenharmony_ci * cm_split_idlest_reg - split CM_IDLEST reg addr into its components
558c2ecf20Sopenharmony_ci * @idlest_reg: CM_IDLEST* virtual address
568c2ecf20Sopenharmony_ci * @prcm_inst: pointer to an s16 to return the PRCM instance offset
578c2ecf20Sopenharmony_ci * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * Given an absolute CM_IDLEST register address @idlest_reg, passes
608c2ecf20Sopenharmony_ci * the PRCM instance offset and IDLEST register ID back to the caller
618c2ecf20Sopenharmony_ci * via the @prcm_inst and @idlest_reg_id.  Returns -EINVAL upon error,
628c2ecf20Sopenharmony_ci * or 0 upon success.  XXX This function is only needed until absolute
638c2ecf20Sopenharmony_ci * register addresses are removed from the OMAP struct clk records.
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_ciint cm_split_idlest_reg(struct clk_omap_reg *idlest_reg, s16 *prcm_inst,
668c2ecf20Sopenharmony_ci			u8 *idlest_reg_id)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	int ret;
698c2ecf20Sopenharmony_ci	if (!cm_ll_data->split_idlest_reg) {
708c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
718c2ecf20Sopenharmony_ci			  __func__);
728c2ecf20Sopenharmony_ci		return -EINVAL;
738c2ecf20Sopenharmony_ci	}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	ret = cm_ll_data->split_idlest_reg(idlest_reg, prcm_inst,
768c2ecf20Sopenharmony_ci					   idlest_reg_id);
778c2ecf20Sopenharmony_ci	*prcm_inst -= cm_base.offset;
788c2ecf20Sopenharmony_ci	return ret;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/**
828c2ecf20Sopenharmony_ci * omap_cm_wait_module_ready - wait for a module to leave idle or standby
838c2ecf20Sopenharmony_ci * @part: PRCM partition
848c2ecf20Sopenharmony_ci * @prcm_mod: PRCM module offset
858c2ecf20Sopenharmony_ci * @idlest_reg: CM_IDLESTx register
868c2ecf20Sopenharmony_ci * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci * Wait for the PRCM to indicate that the module identified by
898c2ecf20Sopenharmony_ci * (@prcm_mod, @idlest_id, @idlest_shift) is clocked.  Return 0 upon
908c2ecf20Sopenharmony_ci * success, -EBUSY if the module doesn't enable in time, or -EINVAL if
918c2ecf20Sopenharmony_ci * no per-SoC wait_module_ready() function pointer has been registered
928c2ecf20Sopenharmony_ci * or if the idlest register is unknown on the SoC.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ciint omap_cm_wait_module_ready(u8 part, s16 prcm_mod, u16 idlest_reg,
958c2ecf20Sopenharmony_ci			      u8 idlest_shift)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	if (!cm_ll_data->wait_module_ready) {
988c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
998c2ecf20Sopenharmony_ci			  __func__);
1008c2ecf20Sopenharmony_ci		return -EINVAL;
1018c2ecf20Sopenharmony_ci	}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	return cm_ll_data->wait_module_ready(part, prcm_mod, idlest_reg,
1048c2ecf20Sopenharmony_ci					     idlest_shift);
1058c2ecf20Sopenharmony_ci}
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/**
1088c2ecf20Sopenharmony_ci * omap_cm_wait_module_idle - wait for a module to enter idle or standby
1098c2ecf20Sopenharmony_ci * @part: PRCM partition
1108c2ecf20Sopenharmony_ci * @prcm_mod: PRCM module offset
1118c2ecf20Sopenharmony_ci * @idlest_reg: CM_IDLESTx register
1128c2ecf20Sopenharmony_ci * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
1138c2ecf20Sopenharmony_ci *
1148c2ecf20Sopenharmony_ci * Wait for the PRCM to indicate that the module identified by
1158c2ecf20Sopenharmony_ci * (@prcm_mod, @idlest_id, @idlest_shift) is no longer clocked.  Return
1168c2ecf20Sopenharmony_ci * 0 upon success, -EBUSY if the module doesn't enable in time, or
1178c2ecf20Sopenharmony_ci * -EINVAL if no per-SoC wait_module_idle() function pointer has been
1188c2ecf20Sopenharmony_ci * registered or if the idlest register is unknown on the SoC.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_ciint omap_cm_wait_module_idle(u8 part, s16 prcm_mod, u16 idlest_reg,
1218c2ecf20Sopenharmony_ci			     u8 idlest_shift)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	if (!cm_ll_data->wait_module_idle) {
1248c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
1258c2ecf20Sopenharmony_ci			  __func__);
1268c2ecf20Sopenharmony_ci		return -EINVAL;
1278c2ecf20Sopenharmony_ci	}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	return cm_ll_data->wait_module_idle(part, prcm_mod, idlest_reg,
1308c2ecf20Sopenharmony_ci					    idlest_shift);
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/**
1348c2ecf20Sopenharmony_ci * omap_cm_module_enable - enable a module
1358c2ecf20Sopenharmony_ci * @mode: target mode for the module
1368c2ecf20Sopenharmony_ci * @part: PRCM partition
1378c2ecf20Sopenharmony_ci * @inst: PRCM instance
1388c2ecf20Sopenharmony_ci * @clkctrl_offs: CM_CLKCTRL register offset for the module
1398c2ecf20Sopenharmony_ci *
1408c2ecf20Sopenharmony_ci * Enables clocks for a module identified by (@part, @inst, @clkctrl_offs)
1418c2ecf20Sopenharmony_ci * making its IO space accessible. Return 0 upon success, -EINVAL if no
1428c2ecf20Sopenharmony_ci * per-SoC module_enable() function pointer has been registered.
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_ciint omap_cm_module_enable(u8 mode, u8 part, u16 inst, u16 clkctrl_offs)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	if (!cm_ll_data->module_enable) {
1478c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
1488c2ecf20Sopenharmony_ci			  __func__);
1498c2ecf20Sopenharmony_ci		return -EINVAL;
1508c2ecf20Sopenharmony_ci	}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	cm_ll_data->module_enable(mode, part, inst, clkctrl_offs);
1538c2ecf20Sopenharmony_ci	return 0;
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/**
1578c2ecf20Sopenharmony_ci * omap_cm_module_disable - disable a module
1588c2ecf20Sopenharmony_ci * @part: PRCM partition
1598c2ecf20Sopenharmony_ci * @inst: PRCM instance
1608c2ecf20Sopenharmony_ci * @clkctrl_offs: CM_CLKCTRL register offset for the module
1618c2ecf20Sopenharmony_ci *
1628c2ecf20Sopenharmony_ci * Disables clocks for a module identified by (@part, @inst, @clkctrl_offs)
1638c2ecf20Sopenharmony_ci * makings its IO space inaccessible. Return 0 upon success, -EINVAL if
1648c2ecf20Sopenharmony_ci * no per-SoC module_disable() function pointer has been registered.
1658c2ecf20Sopenharmony_ci */
1668c2ecf20Sopenharmony_ciint omap_cm_module_disable(u8 part, u16 inst, u16 clkctrl_offs)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	if (!cm_ll_data->module_disable) {
1698c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
1708c2ecf20Sopenharmony_ci			  __func__);
1718c2ecf20Sopenharmony_ci		return -EINVAL;
1728c2ecf20Sopenharmony_ci	}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	cm_ll_data->module_disable(part, inst, clkctrl_offs);
1758c2ecf20Sopenharmony_ci	return 0;
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciu32 omap_cm_xlate_clkctrl(u8 part, u16 inst, u16 clkctrl_offs)
1798c2ecf20Sopenharmony_ci{
1808c2ecf20Sopenharmony_ci	if (!cm_ll_data->xlate_clkctrl) {
1818c2ecf20Sopenharmony_ci		WARN_ONCE(1, "cm: %s: no low-level function defined\n",
1828c2ecf20Sopenharmony_ci			  __func__);
1838c2ecf20Sopenharmony_ci		return 0;
1848c2ecf20Sopenharmony_ci	}
1858c2ecf20Sopenharmony_ci	return cm_ll_data->xlate_clkctrl(part, inst, clkctrl_offs);
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/**
1898c2ecf20Sopenharmony_ci * cm_register - register per-SoC low-level data with the CM
1908c2ecf20Sopenharmony_ci * @cld: low-level per-SoC OMAP CM data & function pointers to register
1918c2ecf20Sopenharmony_ci *
1928c2ecf20Sopenharmony_ci * Register per-SoC low-level OMAP CM data and function pointers with
1938c2ecf20Sopenharmony_ci * the OMAP CM common interface.  The caller must keep the data
1948c2ecf20Sopenharmony_ci * pointed to by @cld valid until it calls cm_unregister() and
1958c2ecf20Sopenharmony_ci * it returns successfully.  Returns 0 upon success, -EINVAL if @cld
1968c2ecf20Sopenharmony_ci * is NULL, or -EEXIST if cm_register() has already been called
1978c2ecf20Sopenharmony_ci * without an intervening cm_unregister().
1988c2ecf20Sopenharmony_ci */
1998c2ecf20Sopenharmony_ciint cm_register(const struct cm_ll_data *cld)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	if (!cld)
2028c2ecf20Sopenharmony_ci		return -EINVAL;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	if (cm_ll_data != &null_cm_ll_data)
2058c2ecf20Sopenharmony_ci		return -EEXIST;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	cm_ll_data = cld;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	return 0;
2108c2ecf20Sopenharmony_ci}
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/**
2138c2ecf20Sopenharmony_ci * cm_unregister - unregister per-SoC low-level data & function pointers
2148c2ecf20Sopenharmony_ci * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
2158c2ecf20Sopenharmony_ci *
2168c2ecf20Sopenharmony_ci * Unregister per-SoC low-level OMAP CM data and function pointers
2178c2ecf20Sopenharmony_ci * that were previously registered with cm_register().  The
2188c2ecf20Sopenharmony_ci * caller may not destroy any of the data pointed to by @cld until
2198c2ecf20Sopenharmony_ci * this function returns successfully.  Returns 0 upon success, or
2208c2ecf20Sopenharmony_ci * -EINVAL if @cld is NULL or if @cld does not match the struct
2218c2ecf20Sopenharmony_ci * cm_ll_data * previously registered by cm_register().
2228c2ecf20Sopenharmony_ci */
2238c2ecf20Sopenharmony_ciint cm_unregister(const struct cm_ll_data *cld)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	if (!cld || cm_ll_data != cld)
2268c2ecf20Sopenharmony_ci		return -EINVAL;
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	cm_ll_data = &null_cm_ll_data;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	return 0;
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
2348c2ecf20Sopenharmony_ci	defined(CONFIG_SOC_DRA7XX)
2358c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data cm_data __initdata = {
2368c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM,
2378c2ecf20Sopenharmony_ci	.init = omap4_cm_init,
2388c2ecf20Sopenharmony_ci};
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data cm2_data __initdata = {
2418c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM2,
2428c2ecf20Sopenharmony_ci	.init = omap4_cm_init,
2438c2ecf20Sopenharmony_ci};
2448c2ecf20Sopenharmony_ci#endif
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_OMAP2
2478c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data omap2_prcm_data __initdata = {
2488c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM,
2498c2ecf20Sopenharmony_ci	.init = omap2xxx_cm_init,
2508c2ecf20Sopenharmony_ci	.flags = CM_NO_CLOCKS | CM_SINGLE_INSTANCE,
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci#endif
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_OMAP3
2558c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data omap3_cm_data __initdata = {
2568c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM,
2578c2ecf20Sopenharmony_ci	.init = omap3xxx_cm_init,
2588c2ecf20Sopenharmony_ci	.flags = CM_SINGLE_INSTANCE,
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	/*
2618c2ecf20Sopenharmony_ci	 * IVA2 offset is a negative value, must offset the cm_base address
2628c2ecf20Sopenharmony_ci	 * by this to get it to positive side on the iomap
2638c2ecf20Sopenharmony_ci	 */
2648c2ecf20Sopenharmony_ci	.offset = -OMAP3430_IVA2_MOD,
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci#endif
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
2698c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data am3_prcm_data __initdata = {
2708c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM,
2718c2ecf20Sopenharmony_ci	.flags = CM_NO_CLOCKS | CM_SINGLE_INSTANCE,
2728c2ecf20Sopenharmony_ci	.init = am33xx_cm_init,
2738c2ecf20Sopenharmony_ci};
2748c2ecf20Sopenharmony_ci#endif
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_AM43XX
2778c2ecf20Sopenharmony_cistatic struct omap_prcm_init_data am4_prcm_data __initdata = {
2788c2ecf20Sopenharmony_ci	.index = TI_CLKM_CM,
2798c2ecf20Sopenharmony_ci	.flags = CM_NO_CLOCKS | CM_SINGLE_INSTANCE,
2808c2ecf20Sopenharmony_ci	.init = omap4_cm_init,
2818c2ecf20Sopenharmony_ci};
2828c2ecf20Sopenharmony_ci#endif
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistatic const struct of_device_id omap_cm_dt_match_table[] __initconst = {
2858c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_OMAP2
2868c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap2-prcm", .data = &omap2_prcm_data },
2878c2ecf20Sopenharmony_ci#endif
2888c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_OMAP3
2898c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap3-cm", .data = &omap3_cm_data },
2908c2ecf20Sopenharmony_ci#endif
2918c2ecf20Sopenharmony_ci#ifdef CONFIG_ARCH_OMAP4
2928c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap4-cm1", .data = &cm_data },
2938c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap4-cm2", .data = &cm2_data },
2948c2ecf20Sopenharmony_ci#endif
2958c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_OMAP5
2968c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap5-cm-core-aon", .data = &cm_data },
2978c2ecf20Sopenharmony_ci	{ .compatible = "ti,omap5-cm-core", .data = &cm2_data },
2988c2ecf20Sopenharmony_ci#endif
2998c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_DRA7XX
3008c2ecf20Sopenharmony_ci	{ .compatible = "ti,dra7-cm-core-aon", .data = &cm_data },
3018c2ecf20Sopenharmony_ci	{ .compatible = "ti,dra7-cm-core", .data = &cm2_data },
3028c2ecf20Sopenharmony_ci#endif
3038c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_AM33XX
3048c2ecf20Sopenharmony_ci	{ .compatible = "ti,am3-prcm", .data = &am3_prcm_data },
3058c2ecf20Sopenharmony_ci#endif
3068c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_AM43XX
3078c2ecf20Sopenharmony_ci	{ .compatible = "ti,am4-prcm", .data = &am4_prcm_data },
3088c2ecf20Sopenharmony_ci#endif
3098c2ecf20Sopenharmony_ci#ifdef CONFIG_SOC_TI81XX
3108c2ecf20Sopenharmony_ci	{ .compatible = "ti,dm814-prcm", .data = &am3_prcm_data },
3118c2ecf20Sopenharmony_ci	{ .compatible = "ti,dm816-prcm", .data = &am3_prcm_data },
3128c2ecf20Sopenharmony_ci#endif
3138c2ecf20Sopenharmony_ci	{ }
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/**
3178c2ecf20Sopenharmony_ci * omap2_cm_base_init - initialize iomappings for the CM drivers
3188c2ecf20Sopenharmony_ci *
3198c2ecf20Sopenharmony_ci * Detects and initializes the iomappings for the CM driver, based
3208c2ecf20Sopenharmony_ci * on the DT data. Returns 0 in success, negative error value
3218c2ecf20Sopenharmony_ci * otherwise.
3228c2ecf20Sopenharmony_ci */
3238c2ecf20Sopenharmony_ciint __init omap2_cm_base_init(void)
3248c2ecf20Sopenharmony_ci{
3258c2ecf20Sopenharmony_ci	struct device_node *np;
3268c2ecf20Sopenharmony_ci	const struct of_device_id *match;
3278c2ecf20Sopenharmony_ci	struct omap_prcm_init_data *data;
3288c2ecf20Sopenharmony_ci	struct resource res;
3298c2ecf20Sopenharmony_ci	int ret;
3308c2ecf20Sopenharmony_ci	struct omap_domain_base *mem = NULL;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	for_each_matching_node_and_match(np, omap_cm_dt_match_table, &match) {
3338c2ecf20Sopenharmony_ci		data = (struct omap_prcm_init_data *)match->data;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci		ret = of_address_to_resource(np, 0, &res);
3368c2ecf20Sopenharmony_ci		if (ret)
3378c2ecf20Sopenharmony_ci			return ret;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci		if (data->index == TI_CLKM_CM)
3408c2ecf20Sopenharmony_ci			mem = &cm_base;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci		if (data->index == TI_CLKM_CM2)
3438c2ecf20Sopenharmony_ci			mem = &cm2_base;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci		data->mem = ioremap(res.start, resource_size(&res));
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci		if (mem) {
3488c2ecf20Sopenharmony_ci			mem->pa = res.start + data->offset;
3498c2ecf20Sopenharmony_ci			mem->va = data->mem + data->offset;
3508c2ecf20Sopenharmony_ci			mem->offset = data->offset;
3518c2ecf20Sopenharmony_ci		}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci		data->np = np;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci		if (data->init && (data->flags & CM_SINGLE_INSTANCE ||
3568c2ecf20Sopenharmony_ci				   (cm_base.va && cm2_base.va)))
3578c2ecf20Sopenharmony_ci			data->init(data);
3588c2ecf20Sopenharmony_ci	}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	return 0;
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci/**
3648c2ecf20Sopenharmony_ci * omap_cm_init - low level init for the CM drivers
3658c2ecf20Sopenharmony_ci *
3668c2ecf20Sopenharmony_ci * Initializes the low level clock infrastructure for CM drivers.
3678c2ecf20Sopenharmony_ci * Returns 0 in success, negative error value in failure.
3688c2ecf20Sopenharmony_ci */
3698c2ecf20Sopenharmony_ciint __init omap_cm_init(void)
3708c2ecf20Sopenharmony_ci{
3718c2ecf20Sopenharmony_ci	struct device_node *np;
3728c2ecf20Sopenharmony_ci	const struct of_device_id *match;
3738c2ecf20Sopenharmony_ci	const struct omap_prcm_init_data *data;
3748c2ecf20Sopenharmony_ci	int ret;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	for_each_matching_node_and_match(np, omap_cm_dt_match_table, &match) {
3778c2ecf20Sopenharmony_ci		data = match->data;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci		if (data->flags & CM_NO_CLOCKS)
3808c2ecf20Sopenharmony_ci			continue;
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci		ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
3838c2ecf20Sopenharmony_ci		if (ret)
3848c2ecf20Sopenharmony_ci			return ret;
3858c2ecf20Sopenharmony_ci	}
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	return 0;
3888c2ecf20Sopenharmony_ci}
389