Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/clock.h |
| 3 | * |
Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 4 | * Copyright (C) 2005-2009 Texas Instruments, Inc. |
Paul Walmsley | 530e544 | 2011-02-25 15:39:28 -0700 | [diff] [blame] | 5 | * Copyright (C) 2004-2011 Nokia Corporation |
Tony Lindgren | a16e970 | 2008-03-18 11:56:39 +0200 | [diff] [blame] | 6 | * |
| 7 | * Contacts: |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 8 | * Richard Woodruff <r-woodruff2@ti.com> |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 9 | * Paul Walmsley |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H |
| 17 | #define __ARCH_ARM_MACH_OMAP2_CLOCK_H |
| 18 | |
Paul Walmsley | 12706c5 | 2011-07-10 05:57:06 -0600 | [diff] [blame] | 19 | #include <linux/kernel.h> |
Paul Walmsley | a135eaa | 2012-09-27 10:33:34 -0600 | [diff] [blame] | 20 | #include <linux/list.h> |
Paul Walmsley | 12706c5 | 2011-07-10 05:57:06 -0600 | [diff] [blame] | 21 | |
Paul Walmsley | e10dd62 | 2012-09-27 10:33:35 -0600 | [diff] [blame] | 22 | #include <linux/clkdev.h> |
Mike Turquette | f9ae32a | 2012-11-07 13:14:47 -0800 | [diff] [blame] | 23 | #include <linux/clk-provider.h> |
Tero Kristo | f38b0dd | 2013-06-12 16:04:34 +0300 | [diff] [blame] | 24 | #include <linux/clk/ti.h> |
Paul Walmsley | e10dd62 | 2012-09-27 10:33:35 -0600 | [diff] [blame] | 25 | |
| 26 | struct omap_clk { |
| 27 | u16 cpu; |
| 28 | struct clk_lookup lk; |
| 29 | }; |
| 30 | |
J Keerthy | 78e52e0 | 2013-03-18 09:57:39 -0600 | [diff] [blame] | 31 | #define CLK(dev, con, ck) \ |
Paul Walmsley | e10dd62 | 2012-09-27 10:33:35 -0600 | [diff] [blame] | 32 | { \ |
Paul Walmsley | e10dd62 | 2012-09-27 10:33:35 -0600 | [diff] [blame] | 33 | .lk = { \ |
| 34 | .dev_id = dev, \ |
| 35 | .con_id = con, \ |
| 36 | .clk = ck, \ |
| 37 | }, \ |
| 38 | } |
| 39 | |
Rajendra Nayak | b5a2366 | 2012-11-10 16:58:40 -0700 | [diff] [blame] | 40 | struct clockdomain; |
Rajendra Nayak | b5a2366 | 2012-11-10 16:58:40 -0700 | [diff] [blame] | 41 | |
Paul Walmsley | 8c725dc | 2012-09-16 10:45:54 -0600 | [diff] [blame] | 42 | #define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \ |
Tomeu Vizoso | 035a61c | 2015-01-23 12:03:30 +0100 | [diff] [blame] | 43 | static struct clk_core _name##_core = { \ |
Paul Walmsley | 8c725dc | 2012-09-16 10:45:54 -0600 | [diff] [blame] | 44 | .name = #_name, \ |
| 45 | .hw = &_name##_hw.hw, \ |
| 46 | .parent_names = _parent_array_name, \ |
| 47 | .num_parents = ARRAY_SIZE(_parent_array_name), \ |
| 48 | .ops = &_clkops_name, \ |
Tomeu Vizoso | 035a61c | 2015-01-23 12:03:30 +0100 | [diff] [blame] | 49 | }; \ |
| 50 | static struct clk _name = { \ |
| 51 | .core = &_name##_core, \ |
Paul Walmsley | 8c725dc | 2012-09-16 10:45:54 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
Afzal Mohammed | 601155b | 2013-01-23 17:12:05 +0530 | [diff] [blame] | 54 | #define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name, \ |
| 55 | _clkops_name, _flags) \ |
Tomeu Vizoso | 035a61c | 2015-01-23 12:03:30 +0100 | [diff] [blame] | 56 | static struct clk_core _name##_core = { \ |
Afzal Mohammed | 601155b | 2013-01-23 17:12:05 +0530 | [diff] [blame] | 57 | .name = #_name, \ |
| 58 | .hw = &_name##_hw.hw, \ |
| 59 | .parent_names = _parent_array_name, \ |
| 60 | .num_parents = ARRAY_SIZE(_parent_array_name), \ |
| 61 | .ops = &_clkops_name, \ |
| 62 | .flags = _flags, \ |
Tomeu Vizoso | 035a61c | 2015-01-23 12:03:30 +0100 | [diff] [blame] | 63 | }; \ |
| 64 | static struct clk _name = { \ |
| 65 | .core = &_name##_core, \ |
Afzal Mohammed | 601155b | 2013-01-23 17:12:05 +0530 | [diff] [blame] | 66 | }; |
| 67 | |
Paul Walmsley | 8c725dc | 2012-09-16 10:45:54 -0600 | [diff] [blame] | 68 | #define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \ |
| 69 | static struct clk_hw_omap _name##_hw = { \ |
| 70 | .hw = { \ |
| 71 | .clk = &_name, \ |
| 72 | }, \ |
| 73 | .clkdm_name = _clkdm_name, \ |
| 74 | }; |
| 75 | |
| 76 | #define DEFINE_CLK_OMAP_MUX(_name, _clkdm_name, _clksel, \ |
| 77 | _clksel_reg, _clksel_mask, \ |
| 78 | _parent_names, _ops) \ |
| 79 | static struct clk _name; \ |
| 80 | static struct clk_hw_omap _name##_hw = { \ |
| 81 | .hw = { \ |
| 82 | .clk = &_name, \ |
| 83 | }, \ |
| 84 | .clksel = _clksel, \ |
| 85 | .clksel_reg = _clksel_reg, \ |
| 86 | .clksel_mask = _clksel_mask, \ |
| 87 | .clkdm_name = _clkdm_name, \ |
| 88 | }; \ |
| 89 | DEFINE_STRUCT_CLK(_name, _parent_names, _ops); |
| 90 | |
| 91 | #define DEFINE_CLK_OMAP_MUX_GATE(_name, _clkdm_name, _clksel, \ |
| 92 | _clksel_reg, _clksel_mask, \ |
| 93 | _enable_reg, _enable_bit, \ |
| 94 | _hwops, _parent_names, _ops) \ |
| 95 | static struct clk _name; \ |
| 96 | static struct clk_hw_omap _name##_hw = { \ |
| 97 | .hw = { \ |
| 98 | .clk = &_name, \ |
| 99 | }, \ |
| 100 | .ops = _hwops, \ |
| 101 | .enable_reg = _enable_reg, \ |
| 102 | .enable_bit = _enable_bit, \ |
| 103 | .clksel = _clksel, \ |
| 104 | .clksel_reg = _clksel_reg, \ |
| 105 | .clksel_mask = _clksel_mask, \ |
| 106 | .clkdm_name = _clkdm_name, \ |
| 107 | }; \ |
| 108 | DEFINE_STRUCT_CLK(_name, _parent_names, _ops); |
| 109 | |
Paul Walmsley | a135eaa | 2012-09-27 10:33:34 -0600 | [diff] [blame] | 110 | /* struct clksel_rate.flags possibilities */ |
| 111 | #define RATE_IN_242X (1 << 0) |
| 112 | #define RATE_IN_243X (1 << 1) |
| 113 | #define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */ |
| 114 | #define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */ |
| 115 | #define RATE_IN_36XX (1 << 4) |
| 116 | #define RATE_IN_4430 (1 << 5) |
| 117 | #define RATE_IN_TI816X (1 << 6) |
| 118 | #define RATE_IN_4460 (1 << 7) |
| 119 | #define RATE_IN_AM33XX (1 << 8) |
| 120 | #define RATE_IN_TI814X (1 << 9) |
| 121 | |
| 122 | #define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X) |
| 123 | #define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS) |
| 124 | #define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX) |
| 125 | #define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460) |
| 126 | |
| 127 | /* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */ |
| 128 | #define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX) |
| 129 | |
| 130 | |
| 131 | /** |
| 132 | * struct clksel_rate - register bitfield values corresponding to clk divisors |
| 133 | * @val: register bitfield value (shifted to bit 0) |
| 134 | * @div: clock divisor corresponding to @val |
| 135 | * @flags: (see "struct clksel_rate.flags possibilities" above) |
| 136 | * |
| 137 | * @val should match the value of a read from struct clk.clksel_reg |
| 138 | * AND'ed with struct clk.clksel_mask, shifted right to bit 0. |
| 139 | * |
| 140 | * @div is the divisor that should be applied to the parent clock's rate |
| 141 | * to produce the current clock's rate. |
| 142 | */ |
| 143 | struct clksel_rate { |
| 144 | u32 val; |
| 145 | u8 div; |
| 146 | u16 flags; |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * struct clksel - available parent clocks, and a pointer to their divisors |
| 151 | * @parent: struct clk * to a possible parent clock |
| 152 | * @rates: available divisors for this parent clock |
| 153 | * |
| 154 | * A struct clksel is always associated with one or more struct clks |
| 155 | * and one or more struct clksel_rates. |
| 156 | */ |
| 157 | struct clksel { |
| 158 | struct clk *parent; |
| 159 | const struct clksel_rate *rates; |
| 160 | }; |
| 161 | |
Russell King | c0bf313 | 2009-02-19 13:29:22 +0000 | [diff] [blame] | 162 | /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */ |
| 163 | #define CORE_CLK_SRC_32K 0x0 |
| 164 | #define CORE_CLK_SRC_DPLL 0x1 |
| 165 | #define CORE_CLK_SRC_DPLL_X2 0x2 |
| 166 | |
| 167 | /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */ |
| 168 | #define OMAP2XXX_EN_DPLL_LPBYPASS 0x1 |
| 169 | #define OMAP2XXX_EN_DPLL_FRBYPASS 0x2 |
| 170 | #define OMAP2XXX_EN_DPLL_LOCKED 0x3 |
| 171 | |
| 172 | /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */ |
| 173 | #define OMAP3XXX_EN_DPLL_LPBYPASS 0x5 |
| 174 | #define OMAP3XXX_EN_DPLL_FRBYPASS 0x6 |
| 175 | #define OMAP3XXX_EN_DPLL_LOCKED 0x7 |
| 176 | |
Rajendra Nayak | 16975a7 | 2009-12-08 18:47:16 -0700 | [diff] [blame] | 177 | /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */ |
| 178 | #define OMAP4XXX_EN_DPLL_MNBYPASS 0x4 |
| 179 | #define OMAP4XXX_EN_DPLL_LPBYPASS 0x5 |
| 180 | #define OMAP4XXX_EN_DPLL_FRBYPASS 0x6 |
| 181 | #define OMAP4XXX_EN_DPLL_LOCKED 0x7 |
| 182 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 183 | u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk); |
| 184 | void omap3_dpll_allow_idle(struct clk_hw_omap *clk); |
| 185 | void omap3_dpll_deny_idle(struct clk_hw_omap *clk); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 186 | void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk); |
| 187 | void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 188 | |
Paul Walmsley | 12706c5 | 2011-07-10 05:57:06 -0600 | [diff] [blame] | 189 | void __init omap2_clk_disable_clkdm_control(void); |
Paul Walmsley | 435699d | 2010-05-18 18:40:24 -0600 | [diff] [blame] | 190 | |
| 191 | /* clkt_clksel.c public functions */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 192 | u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk, |
| 193 | unsigned long target_rate, |
| 194 | u32 *new_div); |
| 195 | u8 omap2_clksel_find_parent_index(struct clk_hw *hw); |
| 196 | unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate); |
| 197 | long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate, |
| 198 | unsigned long *parent_rate); |
| 199 | int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate, |
| 200 | unsigned long parent_rate); |
| 201 | int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val); |
Paul Walmsley | 435699d | 2010-05-18 18:40:24 -0600 | [diff] [blame] | 202 | |
Paul Walmsley | 530e544 | 2011-02-25 15:39:28 -0700 | [diff] [blame] | 203 | /* clkt_iclk.c public functions */ |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame] | 204 | extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk); |
| 205 | extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk); |
Paul Walmsley | 530e544 | 2011-02-25 15:39:28 -0700 | [diff] [blame] | 206 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 207 | unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk); |
Paul Walmsley | 435699d | 2010-05-18 18:40:24 -0600 | [diff] [blame] | 208 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 209 | void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk, |
| 210 | void __iomem **other_reg, |
| 211 | u8 *other_bit); |
| 212 | void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk, |
| 213 | void __iomem **idlest_reg, |
| 214 | u8 *idlest_bit, u8 *idlest_val); |
Rajendra Nayak | 23fb8ba | 2012-06-01 14:02:49 +0530 | [diff] [blame] | 215 | int omap2_clk_enable_autoidle_all(void); |
Tero Kristo | 818b40e | 2013-10-11 19:15:32 +0300 | [diff] [blame] | 216 | int omap2_clk_allow_idle(struct clk *clk); |
| 217 | int omap2_clk_deny_idle(struct clk *clk); |
Paul Walmsley | 4d30e82 | 2010-02-22 22:09:36 -0700 | [diff] [blame] | 218 | int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name); |
| 219 | void omap2_clk_print_new_rates(const char *hfclkin_ck_name, |
| 220 | const char *core_ck_name, |
| 221 | const char *mpu_ck_name); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 222 | |
Tero Kristo | 3ada6b10 | 2013-10-22 11:47:08 +0300 | [diff] [blame] | 223 | u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg); |
| 224 | void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg); |
| 225 | |
Afzal Mohammed | 9954119 | 2011-12-13 10:46:43 -0800 | [diff] [blame] | 226 | extern u16 cpu_mask; |
Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 227 | |
Tero Kristo | 8111e01 | 2014-07-02 11:47:39 +0300 | [diff] [blame] | 228 | /* |
| 229 | * Clock features setup. Used instead of CPU type checks. |
| 230 | */ |
| 231 | struct ti_clk_features { |
| 232 | u32 flags; |
Tero Kristo | a24886e | 2014-07-02 11:47:40 +0300 | [diff] [blame] | 233 | long fint_min; |
| 234 | long fint_max; |
| 235 | long fint_band1_max; |
| 236 | long fint_band2_min; |
Tero Kristo | 512d91c | 2014-07-02 11:47:42 +0300 | [diff] [blame] | 237 | u8 dpll_bypass_vals; |
Tero Kristo | 066edb2 | 2014-07-02 11:47:44 +0300 | [diff] [blame] | 238 | u8 cm_idlest_val; |
Tero Kristo | 8111e01 | 2014-07-02 11:47:39 +0300 | [diff] [blame] | 239 | }; |
Tero Kristo | 2337c5b | 2014-07-02 11:47:43 +0300 | [diff] [blame] | 240 | |
| 241 | #define TI_CLK_DPLL_HAS_FREQSEL (1 << 0) |
Tero Kristo | f0d2f68 | 2014-10-03 16:57:10 +0300 | [diff] [blame] | 242 | #define TI_CLK_DPLL4_DENY_REPROGRAM (1 << 1) |
Tero Kristo | 2337c5b | 2014-07-02 11:47:43 +0300 | [diff] [blame] | 243 | |
Tero Kristo | 8111e01 | 2014-07-02 11:47:39 +0300 | [diff] [blame] | 244 | extern struct ti_clk_features ti_clk_features; |
| 245 | |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 246 | extern const struct clkops clkops_omap2_dflt_wait; |
Russell King | bc51da4 | 2008-11-04 18:59:32 +0000 | [diff] [blame] | 247 | extern const struct clkops clkops_omap2_dflt; |
Russell King | b36ee72 | 2008-11-04 17:59:52 +0000 | [diff] [blame] | 248 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 249 | extern struct clk_functions omap2_clk_functions; |
| 250 | |
Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 251 | extern const struct clksel_rate gpt_32k_rates[]; |
| 252 | extern const struct clksel_rate gpt_sys_rates[]; |
| 253 | extern const struct clksel_rate gfx_l3_rates[]; |
Paul Walmsley | 2241139 | 2011-02-25 15:52:04 -0700 | [diff] [blame] | 254 | extern const struct clksel_rate dsp_ick_rates[]; |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 255 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 256 | extern const struct clk_hw_omap_ops clkhwops_iclk_wait; |
| 257 | extern const struct clk_hw_omap_ops clkhwops_wait; |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame] | 258 | extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait; |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame] | 259 | extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait; |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame] | 260 | extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait; |
| 261 | extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait; |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame] | 262 | extern const struct clk_hw_omap_ops clkhwops_apll54; |
| 263 | extern const struct clk_hw_omap_ops clkhwops_apll96; |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 264 | |
Paul Walmsley | 571efa0 | 2012-05-29 15:26:40 +0530 | [diff] [blame] | 265 | /* clksel_rate blocks shared between OMAP44xx and AM33xx */ |
| 266 | extern const struct clksel_rate div_1_0_rates[]; |
Rajendra Nayak | cb26867 | 2012-11-06 15:41:08 -0700 | [diff] [blame] | 267 | extern const struct clksel_rate div3_1to4_rates[]; |
Paul Walmsley | 571efa0 | 2012-05-29 15:26:40 +0530 | [diff] [blame] | 268 | extern const struct clksel_rate div_1_1_rates[]; |
| 269 | extern const struct clksel_rate div_1_2_rates[]; |
| 270 | extern const struct clksel_rate div_1_3_rates[]; |
| 271 | extern const struct clksel_rate div_1_4_rates[]; |
| 272 | extern const struct clksel_rate div31_1to31_rates[]; |
| 273 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 274 | extern int omap2_clkops_enable_clkdm(struct clk_hw *hw); |
| 275 | extern void omap2_clkops_disable_clkdm(struct clk_hw *hw); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame] | 276 | |
Tero Kristo | 80cbb22 | 2015-02-06 16:00:32 +0200 | [diff] [blame] | 277 | struct regmap; |
| 278 | |
Tero Kristo | 9f029b1 | 2014-10-22 15:15:36 +0300 | [diff] [blame] | 279 | int __init omap2_clk_provider_init(struct device_node *np, int index, |
Tero Kristo | 80cbb22 | 2015-02-06 16:00:32 +0200 | [diff] [blame] | 280 | struct regmap *syscon, void __iomem *mem); |
Tero Kristo | 9f029b1 | 2014-10-22 15:15:36 +0300 | [diff] [blame] | 281 | void __init omap2_clk_legacy_provider_init(int index, void __iomem *mem); |
| 282 | |
Tero Kristo | 8111e01 | 2014-07-02 11:47:39 +0300 | [diff] [blame] | 283 | void __init ti_clk_init_features(void); |
Paul Walmsley | 543d937 | 2008-03-18 10:22:06 +0200 | [diff] [blame] | 284 | #endif |