Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP clockdomain support |
| 3 | * |
| 4 | * Copyright (C) 2013 Texas Instruments, Inc. |
| 5 | * |
| 6 | * Tero Kristo <t-kristo@ti.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 13 | * kind, whether express or implied; without even the implied warranty |
| 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Stephen Boyd | 1b29e60 | 2015-06-19 15:00:46 -0700 | [diff] [blame] | 18 | #include <linux/clk.h> |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 19 | #include <linux/clk-provider.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/of_address.h> |
| 23 | #include <linux/clk/ti.h> |
| 24 | |
Tero Kristo | e9e6308 | 2015-04-27 21:55:42 +0300 | [diff] [blame] | 25 | #include "clock.h" |
| 26 | |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 27 | #undef pr_fmt |
| 28 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 29 | |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 30 | /** |
| 31 | * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw |
| 32 | * @hw: struct clk_hw * of the clock being enabled |
| 33 | * |
| 34 | * Increment the usecount of the clockdomain of the clock pointed to |
| 35 | * by @hw; if the usecount is 1, the clockdomain will be "enabled." |
| 36 | * Only needed for clocks that don't use omap2_dflt_clk_enable() as |
| 37 | * their enable function pointer. Passes along the return value of |
| 38 | * clkdm_clk_enable(), -EINVAL if @hw is not associated with a |
| 39 | * clockdomain, or 0 if clock framework-based clockdomain control is |
| 40 | * not implemented. |
| 41 | */ |
| 42 | int omap2_clkops_enable_clkdm(struct clk_hw *hw) |
| 43 | { |
| 44 | struct clk_hw_omap *clk; |
| 45 | int ret = 0; |
| 46 | |
| 47 | clk = to_clk_hw_omap(hw); |
| 48 | |
| 49 | if (unlikely(!clk->clkdm)) { |
| 50 | pr_err("%s: %s: no clkdm set ?!\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 51 | clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | } |
| 54 | |
| 55 | if (unlikely(clk->enable_reg)) |
| 56 | pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 57 | clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 58 | |
| 59 | if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) { |
| 60 | pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n", |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 61 | __func__, clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk); |
| 66 | WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n", |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 67 | __func__, clk_hw_get_name(hw), clk->clkdm_name, ret); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw |
| 74 | * @hw: struct clk_hw * of the clock being disabled |
| 75 | * |
| 76 | * Decrement the usecount of the clockdomain of the clock pointed to |
| 77 | * by @hw; if the usecount is 0, the clockdomain will be "disabled." |
| 78 | * Only needed for clocks that don't use omap2_dflt_clk_disable() as their |
| 79 | * disable function pointer. No return value. |
| 80 | */ |
| 81 | void omap2_clkops_disable_clkdm(struct clk_hw *hw) |
| 82 | { |
| 83 | struct clk_hw_omap *clk; |
| 84 | |
| 85 | clk = to_clk_hw_omap(hw); |
| 86 | |
| 87 | if (unlikely(!clk->clkdm)) { |
| 88 | pr_err("%s: %s: no clkdm set ?!\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 89 | clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
| 93 | if (unlikely(clk->enable_reg)) |
| 94 | pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 95 | clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 96 | |
| 97 | if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) { |
| 98 | pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n", |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 99 | __func__, clk_hw_get_name(hw)); |
Tero Kristo | bd86cfd | 2015-03-03 16:22:50 +0200 | [diff] [blame] | 100 | return; |
| 101 | } |
| 102 | |
| 103 | ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk); |
| 104 | } |
| 105 | |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 106 | static void __init of_ti_clockdomain_setup(struct device_node *node) |
| 107 | { |
| 108 | struct clk *clk; |
| 109 | struct clk_hw *clk_hw; |
| 110 | const char *clkdm_name = node->name; |
| 111 | int i; |
Stephen Boyd | 921bacf | 2016-02-19 17:49:23 -0800 | [diff] [blame] | 112 | unsigned int num_clks; |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 113 | |
Geert Uytterhoeven | f71355b | 2015-05-29 11:25:47 +0200 | [diff] [blame] | 114 | num_clks = of_clk_get_parent_count(node); |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 115 | |
| 116 | for (i = 0; i < num_clks; i++) { |
| 117 | clk = of_clk_get(node, i); |
Sebastian Andrzej Siewior | 319f127 | 2014-09-18 16:33:27 +0200 | [diff] [blame] | 118 | if (IS_ERR(clk)) { |
| 119 | pr_err("%s: Failed get %s' clock nr %d (%ld)\n", |
| 120 | __func__, node->full_name, i, PTR_ERR(clk)); |
| 121 | continue; |
| 122 | } |
Stephen Boyd | 98d8a60 | 2015-06-29 16:56:30 -0700 | [diff] [blame] | 123 | clk_hw = __clk_get_hw(clk); |
| 124 | if (clk_hw_get_flags(clk_hw) & CLK_IS_BASIC) { |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 125 | pr_warn("can't setup clkdm for basic clk %s\n", |
| 126 | __clk_get_name(clk)); |
| 127 | continue; |
| 128 | } |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 129 | to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name; |
| 130 | omap2_init_clk_clkdm(clk_hw); |
| 131 | } |
| 132 | } |
| 133 | |
Fabian Frederick | f375573 | 2015-03-31 20:50:42 +0200 | [diff] [blame] | 134 | static const struct of_device_id ti_clkdm_match_table[] __initconst = { |
Tero Kristo | 3cd4a59 | 2013-08-21 19:39:15 +0300 | [diff] [blame] | 135 | { .compatible = "ti,clockdomain" }, |
| 136 | { } |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * ti_dt_clockdomains_setup - setup device tree clockdomains |
| 141 | * |
| 142 | * Initializes clockdomain nodes for a SoC. This parses through all the |
| 143 | * nodes with compatible = "ti,clockdomain", and add the clockdomain |
| 144 | * info for all the clocks listed under these. This function shall be |
| 145 | * called after rest of the DT clock init has completed and all |
| 146 | * clock nodes have been registered. |
| 147 | */ |
| 148 | void __init ti_dt_clockdomains_setup(void) |
| 149 | { |
| 150 | struct device_node *np; |
| 151 | for_each_matching_node(np, ti_clkdm_match_table) { |
| 152 | of_ti_clockdomain_setup(np); |
| 153 | } |
| 154 | } |