]> rtime.felk.cvut.cz Git - can-eth-gw-linux.git/blob - arch/arm/mach-omap2/cm_common.c
0bab493ec133928b8564e42c25cf64051411023d
[can-eth-gw-linux.git] / arch / arm / mach-omap2 / cm_common.c
1 /*
2  * OMAP2+ common Clock Management (CM) IP block functions
3  *
4  * Copyright (C) 2012 Texas Instruments, Inc.
5  * Paul Walmsley
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * XXX This code should eventually be moved to a CM driver.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16
17 #include "cm2xxx.h"
18 #include "cm3xxx.h"
19 #include "cm44xx.h"
20 #include "common.h"
21
22 /*
23  * cm_ll_data: function pointers to SoC-specific implementations of
24  * common CM functions
25  */
26 static struct cm_ll_data null_cm_ll_data;
27 static struct cm_ll_data *cm_ll_data = &null_cm_ll_data;
28
29 /* cm_base: base virtual address of the CM IP block */
30 void __iomem *cm_base;
31
32 /* cm2_base: base virtual address of the CM2 IP block (OMAP44xx only) */
33 void __iomem *cm2_base;
34
35 /**
36  * omap2_set_globals_cm - set the CM/CM2 base addresses (for early use)
37  * @cm: CM base virtual address
38  * @cm2: CM2 base virtual address (if present on the booted SoC)
39  *
40  * XXX Will be replaced when the PRM/CM drivers are completed.
41  */
42 void __init omap2_set_globals_cm(void __iomem *cm, void __iomem *cm2)
43 {
44         cm_base = cm;
45         cm2_base = cm2;
46 }
47
48 /**
49  * cm_split_idlest_reg - split CM_IDLEST reg addr into its components
50  * @idlest_reg: CM_IDLEST* virtual address
51  * @prcm_inst: pointer to an s16 to return the PRCM instance offset
52  * @idlest_reg_id: pointer to a u8 to return the CM_IDLESTx register ID
53  *
54  * Given an absolute CM_IDLEST register address @idlest_reg, passes
55  * the PRCM instance offset and IDLEST register ID back to the caller
56  * via the @prcm_inst and @idlest_reg_id.  Returns -EINVAL upon error,
57  * or 0 upon success.  XXX This function is only needed until absolute
58  * register addresses are removed from the OMAP struct clk records.
59  */
60 int cm_split_idlest_reg(void __iomem *idlest_reg, s16 *prcm_inst,
61                         u8 *idlest_reg_id)
62 {
63         if (!cm_ll_data->split_idlest_reg) {
64                 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
65                           __func__);
66                 return -EINVAL;
67         }
68
69         return cm_ll_data->split_idlest_reg(idlest_reg, prcm_inst,
70                                            idlest_reg_id);
71 }
72
73 /**
74  * cm_wait_module_ready - wait for a module to leave idle or standby
75  * @prcm_mod: PRCM module offset
76  * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
77  * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
78  *
79  * Wait for the PRCM to indicate that the module identified by
80  * (@prcm_mod, @idlest_id, @idlest_shift) is clocked.  Return 0 upon
81  * success, -EBUSY if the module doesn't enable in time, or -EINVAL if
82  * no per-SoC wait_module_ready() function pointer has been registered
83  * or if the idlest register is unknown on the SoC.
84  */
85 int cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift)
86 {
87         if (!cm_ll_data->wait_module_ready) {
88                 WARN_ONCE(1, "cm: %s: no low-level function defined\n",
89                           __func__);
90                 return -EINVAL;
91         }
92
93         return cm_ll_data->wait_module_ready(prcm_mod, idlest_id, idlest_shift);
94 }
95
96 /**
97  * cm_register - register per-SoC low-level data with the CM
98  * @cld: low-level per-SoC OMAP CM data & function pointers to register
99  *
100  * Register per-SoC low-level OMAP CM data and function pointers with
101  * the OMAP CM common interface.  The caller must keep the data
102  * pointed to by @cld valid until it calls cm_unregister() and
103  * it returns successfully.  Returns 0 upon success, -EINVAL if @cld
104  * is NULL, or -EEXIST if cm_register() has already been called
105  * without an intervening cm_unregister().
106  */
107 int cm_register(struct cm_ll_data *cld)
108 {
109         if (!cld)
110                 return -EINVAL;
111
112         if (cm_ll_data != &null_cm_ll_data)
113                 return -EEXIST;
114
115         cm_ll_data = cld;
116
117         return 0;
118 }
119
120 /**
121  * cm_unregister - unregister per-SoC low-level data & function pointers
122  * @cld: low-level per-SoC OMAP CM data & function pointers to unregister
123  *
124  * Unregister per-SoC low-level OMAP CM data and function pointers
125  * that were previously registered with cm_register().  The
126  * caller may not destroy any of the data pointed to by @cld until
127  * this function returns successfully.  Returns 0 upon success, or
128  * -EINVAL if @cld is NULL or if @cld does not match the struct
129  * cm_ll_data * previously registered by cm_register().
130  */
131 int cm_unregister(struct cm_ll_data *cld)
132 {
133         if (!cld || cm_ll_data != cld)
134                 return -EINVAL;
135
136         cm_ll_data = &null_cm_ll_data;
137
138         return 0;
139 }