Tero Kristo | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 1 | /* |
| 2 | * TI clock 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 | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 19 | #include <linux/clk-provider.h> |
| 20 | #include <linux/clkdev.h> |
| 21 | #include <linux/clk/ti.h> |
| 22 | #include <linux/of.h> |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 23 | #include <linux/of_address.h> |
| 24 | #include <linux/list.h> |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 25 | #include <linux/regmap.h> |
| 26 | #include <linux/bootmem.h> |
Tero Kristo | 21f0bf2 | 2016-09-29 12:00:57 +0300 | [diff] [blame] | 27 | #include <linux/device.h> |
Tero Kristo | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 28 | |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 29 | #include "clock.h" |
| 30 | |
Tero Kristo | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 31 | #undef pr_fmt |
| 32 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 33 | |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 34 | struct ti_clk_ll_ops *ti_clk_ll_ops; |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 35 | static struct device_node *clocks_node_ptr[CLK_MAX_MEMMAPS]; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 36 | |
Stephen Boyd | 3fe6d69 | 2015-07-15 12:03:52 -0700 | [diff] [blame] | 37 | static struct ti_clk_features ti_clk_features; |
Tero Kristo | f3b19aa | 2015-02-27 17:54:14 +0200 | [diff] [blame] | 38 | |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 39 | struct clk_iomap { |
| 40 | struct regmap *regmap; |
| 41 | void __iomem *mem; |
| 42 | }; |
| 43 | |
| 44 | static struct clk_iomap *clk_memmaps[CLK_MAX_MEMMAPS]; |
| 45 | |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 46 | static void clk_memmap_writel(u32 val, const struct clk_omap_reg *reg) |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 47 | { |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 48 | struct clk_iomap *io = clk_memmaps[reg->index]; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 49 | |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 50 | if (reg->ptr) |
| 51 | writel_relaxed(val, reg->ptr); |
| 52 | else if (io->regmap) |
| 53 | regmap_write(io->regmap, reg->offset, val); |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 54 | else |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 55 | writel_relaxed(val, io->mem + reg->offset); |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 56 | } |
| 57 | |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 58 | static u32 clk_memmap_readl(const struct clk_omap_reg *reg) |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 59 | { |
| 60 | u32 val; |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 61 | struct clk_iomap *io = clk_memmaps[reg->index]; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 62 | |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 63 | if (reg->ptr) |
| 64 | val = readl_relaxed(reg->ptr); |
| 65 | else if (io->regmap) |
| 66 | regmap_read(io->regmap, reg->offset, &val); |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 67 | else |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 68 | val = readl_relaxed(io->mem + reg->offset); |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 69 | |
| 70 | return val; |
| 71 | } |
| 72 | |
Tero Kristo | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 73 | /** |
Tero Kristo | e9e6308 | 2015-04-27 21:55:42 +0300 | [diff] [blame] | 74 | * ti_clk_setup_ll_ops - setup low level clock operations |
| 75 | * @ops: low level clock ops descriptor |
| 76 | * |
| 77 | * Sets up low level clock operations for TI clock driver. This is used |
| 78 | * to provide various callbacks for the clock driver towards platform |
| 79 | * specific code. Returns 0 on success, -EBUSY if ll_ops have been |
| 80 | * registered already. |
| 81 | */ |
| 82 | int ti_clk_setup_ll_ops(struct ti_clk_ll_ops *ops) |
| 83 | { |
| 84 | if (ti_clk_ll_ops) { |
| 85 | pr_err("Attempt to register ll_ops multiple times.\n"); |
| 86 | return -EBUSY; |
| 87 | } |
| 88 | |
| 89 | ti_clk_ll_ops = ops; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 90 | ops->clk_readl = clk_memmap_readl; |
| 91 | ops->clk_writel = clk_memmap_writel; |
Tero Kristo | e9e6308 | 2015-04-27 21:55:42 +0300 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Tero Kristo | a8acecc | 2013-07-18 11:52:33 +0300 | [diff] [blame] | 96 | /** |
| 97 | * ti_dt_clocks_register - register DT alias clocks during boot |
| 98 | * @oclks: list of clocks to register |
| 99 | * |
| 100 | * Register alias or non-standard DT clock entries during boot. By |
| 101 | * default, DT clocks are found based on their node name. If any |
| 102 | * additional con-id / dev-id -> clock mapping is required, use this |
| 103 | * function to list these. |
| 104 | */ |
| 105 | void __init ti_dt_clocks_register(struct ti_dt_clk oclks[]) |
| 106 | { |
| 107 | struct ti_dt_clk *c; |
| 108 | struct device_node *node; |
| 109 | struct clk *clk; |
| 110 | struct of_phandle_args clkspec; |
| 111 | |
| 112 | for (c = oclks; c->node_name != NULL; c++) { |
| 113 | node = of_find_node_by_name(NULL, c->node_name); |
| 114 | clkspec.np = node; |
| 115 | clk = of_clk_get_from_provider(&clkspec); |
| 116 | |
| 117 | if (!IS_ERR(clk)) { |
| 118 | c->lk.clk = clk; |
| 119 | clkdev_add(&c->lk); |
| 120 | } else { |
| 121 | pr_warn("failed to lookup clock node %s\n", |
| 122 | c->node_name); |
| 123 | } |
| 124 | } |
| 125 | } |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 126 | |
| 127 | struct clk_init_item { |
| 128 | struct device_node *node; |
| 129 | struct clk_hw *hw; |
| 130 | ti_of_clk_init_cb_t func; |
| 131 | struct list_head link; |
| 132 | }; |
| 133 | |
| 134 | static LIST_HEAD(retry_list); |
| 135 | |
| 136 | /** |
| 137 | * ti_clk_retry_init - retries a failed clock init at later phase |
| 138 | * @node: device not for the clock |
| 139 | * @hw: partially initialized clk_hw struct for the clock |
| 140 | * @func: init function to be called for the clock |
| 141 | * |
| 142 | * Adds a failed clock init to the retry list. The retry list is parsed |
| 143 | * once all the other clocks have been initialized. |
| 144 | */ |
| 145 | int __init ti_clk_retry_init(struct device_node *node, struct clk_hw *hw, |
| 146 | ti_of_clk_init_cb_t func) |
| 147 | { |
| 148 | struct clk_init_item *retry; |
| 149 | |
| 150 | pr_debug("%s: adding to retry list...\n", node->name); |
| 151 | retry = kzalloc(sizeof(*retry), GFP_KERNEL); |
| 152 | if (!retry) |
| 153 | return -ENOMEM; |
| 154 | |
| 155 | retry->node = node; |
| 156 | retry->func = func; |
| 157 | retry->hw = hw; |
| 158 | list_add(&retry->link, &retry_list); |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * ti_clk_get_reg_addr - get register address for a clock register |
| 165 | * @node: device node for the clock |
| 166 | * @index: register index from the clock node |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 167 | * @reg: pointer to target register struct |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 168 | * |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 169 | * Builds clock register address from device tree information, and returns |
| 170 | * the data via the provided output pointer @reg. Returns 0 on success, |
| 171 | * negative error value on failure. |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 172 | */ |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 173 | int ti_clk_get_reg_addr(struct device_node *node, int index, |
| 174 | struct clk_omap_reg *reg) |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 175 | { |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 176 | u32 val; |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 177 | int i; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 178 | |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 179 | for (i = 0; i < CLK_MAX_MEMMAPS; i++) { |
| 180 | if (clocks_node_ptr[i] == node->parent) |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | if (i == CLK_MAX_MEMMAPS) { |
| 185 | pr_err("clk-provider not found for %s!\n", node->name); |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 186 | return -ENOENT; |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | reg->index = i; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 190 | |
| 191 | if (of_property_read_u32_index(node, "reg", index, &val)) { |
| 192 | pr_err("%s must have reg[%d]!\n", node->name, index); |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 193 | return -EINVAL; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | reg->offset = val; |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 197 | reg->ptr = NULL; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 198 | |
Tero Kristo | 6c0afb5 | 2017-02-09 11:24:37 +0200 | [diff] [blame] | 199 | return 0; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /** |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 203 | * omap2_clk_provider_init - init master clock provider |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 204 | * @parent: master node |
| 205 | * @index: internal index for clk_reg_ops |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 206 | * @syscon: syscon regmap pointer for accessing clock registers |
| 207 | * @mem: iomem pointer for the clock provider memory area, only used if |
| 208 | * syscon is not provided |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 209 | * |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 210 | * Initializes a master clock IP block. This basically sets up the |
| 211 | * mapping from clocks node to the memory map index. All the clocks |
| 212 | * are then initialized through the common of_clk_init call, and the |
| 213 | * clocks will access their memory maps based on the node layout. |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 214 | * Returns 0 in success. |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 215 | */ |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 216 | int __init omap2_clk_provider_init(struct device_node *parent, int index, |
| 217 | struct regmap *syscon, void __iomem *mem) |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 218 | { |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 219 | struct device_node *clocks; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 220 | struct clk_iomap *io; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 221 | |
| 222 | /* get clocks for this parent */ |
| 223 | clocks = of_get_child_by_name(parent, "clocks"); |
| 224 | if (!clocks) { |
| 225 | pr_err("%s missing 'clocks' child node.\n", parent->name); |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 226 | return -EINVAL; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 227 | } |
| 228 | |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 229 | /* add clocks node info */ |
| 230 | clocks_node_ptr[index] = clocks; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 231 | |
| 232 | io = kzalloc(sizeof(*io), GFP_KERNEL); |
Stephen Boyd | f645f72d | 2015-07-15 11:55:42 -0700 | [diff] [blame] | 233 | if (!io) |
| 234 | return -ENOMEM; |
Tero Kristo | 989feaf | 2015-04-27 22:23:06 +0300 | [diff] [blame] | 235 | |
| 236 | io->regmap = syscon; |
| 237 | io->mem = mem; |
| 238 | |
| 239 | clk_memmaps[index] = io; |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * omap2_clk_legacy_provider_init - initialize a legacy clock provider |
| 246 | * @index: index for the clock provider |
| 247 | * @mem: iomem pointer for the clock provider memory area |
| 248 | * |
| 249 | * Initializes a legacy clock provider memory mapping. |
| 250 | */ |
| 251 | void __init omap2_clk_legacy_provider_init(int index, void __iomem *mem) |
| 252 | { |
| 253 | struct clk_iomap *io; |
| 254 | |
| 255 | io = memblock_virt_alloc(sizeof(*io), 0); |
| 256 | |
| 257 | io->mem = mem; |
| 258 | |
| 259 | clk_memmaps[index] = io; |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 260 | } |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 261 | |
Tero Kristo | c08ee14 | 2014-09-12 15:01:57 +0300 | [diff] [blame] | 262 | /** |
| 263 | * ti_dt_clk_init_retry_clks - init clocks from the retry list |
| 264 | * |
| 265 | * Initializes any clocks that have failed to initialize before, |
| 266 | * reasons being missing parent node(s) during earlier init. This |
| 267 | * typically happens only for DPLLs which need to have both of their |
| 268 | * parent clocks ready during init. |
| 269 | */ |
| 270 | void ti_dt_clk_init_retry_clks(void) |
| 271 | { |
| 272 | struct clk_init_item *retry; |
| 273 | struct clk_init_item *tmp; |
| 274 | int retries = 5; |
| 275 | |
| 276 | while (!list_empty(&retry_list) && retries) { |
| 277 | list_for_each_entry_safe(retry, tmp, &retry_list, link) { |
| 278 | pr_debug("retry-init: %s\n", retry->node->name); |
| 279 | retry->func(retry->hw, retry->node); |
| 280 | list_del(&retry->link); |
| 281 | kfree(retry); |
| 282 | } |
| 283 | retries--; |
Tero Kristo | 819b486 | 2013-10-22 11:39:36 +0300 | [diff] [blame] | 284 | } |
| 285 | } |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 286 | |
Arnd Bergmann | 6793a30a | 2015-02-03 17:59:32 +0100 | [diff] [blame] | 287 | #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_ATAGS) |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 288 | void __init ti_clk_patch_legacy_clks(struct ti_clk **patch) |
| 289 | { |
| 290 | while (*patch) { |
| 291 | memcpy((*patch)->patch, *patch, sizeof(**patch)); |
| 292 | patch++; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | struct clk __init *ti_clk_register_clk(struct ti_clk *setup) |
| 297 | { |
| 298 | struct clk *clk; |
| 299 | struct ti_clk_fixed *fixed; |
| 300 | struct ti_clk_fixed_factor *fixed_factor; |
| 301 | struct clk_hw *clk_hw; |
Tero Kristo | 1ae79c4 | 2016-09-29 12:06:40 +0300 | [diff] [blame] | 302 | int ret; |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 303 | |
| 304 | if (setup->clk) |
| 305 | return setup->clk; |
| 306 | |
| 307 | switch (setup->type) { |
| 308 | case TI_CLK_FIXED: |
| 309 | fixed = setup->data; |
| 310 | |
Stephen Boyd | 45e2115 | 2016-03-01 11:00:03 -0800 | [diff] [blame] | 311 | clk = clk_register_fixed_rate(NULL, setup->name, NULL, 0, |
| 312 | fixed->frequency); |
Tero Kristo | 1ae79c4 | 2016-09-29 12:06:40 +0300 | [diff] [blame] | 313 | if (!IS_ERR(clk)) { |
| 314 | ret = ti_clk_add_alias(NULL, clk, setup->name); |
| 315 | if (ret) { |
| 316 | clk_unregister(clk); |
| 317 | clk = ERR_PTR(ret); |
| 318 | } |
| 319 | } |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 320 | break; |
Tero Kristo | 7c18a65 | 2014-12-16 18:20:47 +0200 | [diff] [blame] | 321 | case TI_CLK_MUX: |
| 322 | clk = ti_clk_register_mux(setup); |
| 323 | break; |
Tero Kristo | d96f774 | 2014-12-16 18:20:50 +0200 | [diff] [blame] | 324 | case TI_CLK_DIVIDER: |
| 325 | clk = ti_clk_register_divider(setup); |
| 326 | break; |
Tero Kristo | b26bcf9 | 2014-12-16 18:20:52 +0200 | [diff] [blame] | 327 | case TI_CLK_COMPOSITE: |
| 328 | clk = ti_clk_register_composite(setup); |
| 329 | break; |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 330 | case TI_CLK_FIXED_FACTOR: |
| 331 | fixed_factor = setup->data; |
| 332 | |
| 333 | clk = clk_register_fixed_factor(NULL, setup->name, |
| 334 | fixed_factor->parent, |
| 335 | 0, fixed_factor->mult, |
| 336 | fixed_factor->div); |
Tero Kristo | 1ae79c4 | 2016-09-29 12:06:40 +0300 | [diff] [blame] | 337 | if (!IS_ERR(clk)) { |
| 338 | ret = ti_clk_add_alias(NULL, clk, setup->name); |
| 339 | if (ret) { |
| 340 | clk_unregister(clk); |
| 341 | clk = ERR_PTR(ret); |
| 342 | } |
| 343 | } |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 344 | break; |
Tero Kristo | f187616 | 2014-12-16 18:20:48 +0200 | [diff] [blame] | 345 | case TI_CLK_GATE: |
| 346 | clk = ti_clk_register_gate(setup); |
| 347 | break; |
Tero Kristo | ed405a2 | 2015-01-29 22:24:28 +0200 | [diff] [blame] | 348 | case TI_CLK_DPLL: |
| 349 | clk = ti_clk_register_dpll(setup); |
| 350 | break; |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 351 | default: |
| 352 | pr_err("bad type for %s!\n", setup->name); |
| 353 | clk = ERR_PTR(-EINVAL); |
| 354 | } |
| 355 | |
| 356 | if (!IS_ERR(clk)) { |
| 357 | setup->clk = clk; |
| 358 | if (setup->clkdm_name) { |
Stephen Boyd | 98d8a60 | 2015-06-29 16:56:30 -0700 | [diff] [blame] | 359 | clk_hw = __clk_get_hw(clk); |
| 360 | if (clk_hw_get_flags(clk_hw) & CLK_IS_BASIC) { |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 361 | pr_warn("can't setup clkdm for basic clk %s\n", |
| 362 | setup->name); |
| 363 | } else { |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 364 | to_clk_hw_omap(clk_hw)->clkdm_name = |
| 365 | setup->clkdm_name; |
| 366 | omap2_init_clk_clkdm(clk_hw); |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return clk; |
| 372 | } |
| 373 | |
| 374 | int __init ti_clk_register_legacy_clks(struct ti_clk_alias *clks) |
| 375 | { |
| 376 | struct clk *clk; |
| 377 | bool retry; |
| 378 | struct ti_clk_alias *retry_clk; |
| 379 | struct ti_clk_alias *tmp; |
| 380 | |
| 381 | while (clks->clk) { |
| 382 | clk = ti_clk_register_clk(clks->clk); |
| 383 | if (IS_ERR(clk)) { |
| 384 | if (PTR_ERR(clk) == -EAGAIN) { |
| 385 | list_add(&clks->link, &retry_list); |
| 386 | } else { |
| 387 | pr_err("register for %s failed: %ld\n", |
| 388 | clks->clk->name, PTR_ERR(clk)); |
| 389 | return PTR_ERR(clk); |
| 390 | } |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 391 | } |
| 392 | clks++; |
| 393 | } |
| 394 | |
| 395 | retry = true; |
| 396 | |
| 397 | while (!list_empty(&retry_list) && retry) { |
| 398 | retry = false; |
| 399 | list_for_each_entry_safe(retry_clk, tmp, &retry_list, link) { |
| 400 | pr_debug("retry-init: %s\n", retry_clk->clk->name); |
| 401 | clk = ti_clk_register_clk(retry_clk->clk); |
| 402 | if (IS_ERR(clk)) { |
| 403 | if (PTR_ERR(clk) == -EAGAIN) { |
| 404 | continue; |
| 405 | } else { |
| 406 | pr_err("register for %s failed: %ld\n", |
| 407 | retry_clk->clk->name, |
| 408 | PTR_ERR(clk)); |
| 409 | return PTR_ERR(clk); |
| 410 | } |
| 411 | } else { |
| 412 | retry = true; |
Tero Kristo | c82f895 | 2014-12-16 18:20:46 +0200 | [diff] [blame] | 413 | list_del(&retry_clk->link); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
Arnd Bergmann | 6793a30a | 2015-02-03 17:59:32 +0100 | [diff] [blame] | 420 | #endif |
Tero Kristo | f3b19aa | 2015-02-27 17:54:14 +0200 | [diff] [blame] | 421 | |
Arnd Bergmann | fc04f27d | 2017-04-19 19:44:56 +0200 | [diff] [blame] | 422 | static const struct of_device_id simple_clk_match_table[] __initconst = { |
| 423 | { .compatible = "fixed-clock" }, |
| 424 | { .compatible = "fixed-factor-clock" }, |
| 425 | { } |
| 426 | }; |
| 427 | |
Tero Kristo | f3b19aa | 2015-02-27 17:54:14 +0200 | [diff] [blame] | 428 | /** |
Tero Kristo | c17435c | 2016-09-29 12:05:00 +0300 | [diff] [blame] | 429 | * ti_clk_add_aliases - setup clock aliases |
| 430 | * |
| 431 | * Sets up any missing clock aliases. No return value. |
| 432 | */ |
| 433 | void __init ti_clk_add_aliases(void) |
| 434 | { |
| 435 | struct device_node *np; |
| 436 | struct clk *clk; |
| 437 | |
| 438 | for_each_matching_node(np, simple_clk_match_table) { |
| 439 | struct of_phandle_args clkspec; |
| 440 | |
| 441 | clkspec.np = np; |
| 442 | clk = of_clk_get_from_provider(&clkspec); |
| 443 | |
| 444 | ti_clk_add_alias(NULL, clk, np->name); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /** |
Tero Kristo | f3b19aa | 2015-02-27 17:54:14 +0200 | [diff] [blame] | 449 | * ti_clk_setup_features - setup clock features flags |
| 450 | * @features: features definition to use |
| 451 | * |
| 452 | * Initializes the clock driver features flags based on platform |
| 453 | * provided data. No return value. |
| 454 | */ |
| 455 | void __init ti_clk_setup_features(struct ti_clk_features *features) |
| 456 | { |
| 457 | memcpy(&ti_clk_features, features, sizeof(*features)); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * ti_clk_get_features - get clock driver features flags |
| 462 | * |
| 463 | * Get TI clock driver features description. Returns a pointer |
| 464 | * to the current feature setup. |
| 465 | */ |
| 466 | const struct ti_clk_features *ti_clk_get_features(void) |
| 467 | { |
| 468 | return &ti_clk_features; |
| 469 | } |
Tero Kristo | a5aa8a6 | 2015-03-03 10:51:01 +0200 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * omap2_clk_enable_init_clocks - prepare & enable a list of clocks |
| 473 | * @clk_names: ptr to an array of strings of clock names to enable |
| 474 | * @num_clocks: number of clock names in @clk_names |
| 475 | * |
| 476 | * Prepare and enable a list of clocks, named by @clk_names. No |
| 477 | * return value. XXX Deprecated; only needed until these clocks are |
| 478 | * properly claimed and enabled by the drivers or core code that uses |
| 479 | * them. XXX What code disables & calls clk_put on these clocks? |
| 480 | */ |
| 481 | void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks) |
| 482 | { |
| 483 | struct clk *init_clk; |
| 484 | int i; |
| 485 | |
| 486 | for (i = 0; i < num_clocks; i++) { |
| 487 | init_clk = clk_get(NULL, clk_names[i]); |
| 488 | if (WARN(IS_ERR(init_clk), "could not find init clock %s\n", |
| 489 | clk_names[i])) |
| 490 | continue; |
| 491 | clk_prepare_enable(init_clk); |
| 492 | } |
| 493 | } |
Tero Kristo | 21f0bf2 | 2016-09-29 12:00:57 +0300 | [diff] [blame] | 494 | |
| 495 | /** |
| 496 | * ti_clk_add_alias - add a clock alias for a TI clock |
| 497 | * @dev: device alias for this clock |
| 498 | * @clk: clock handle to create alias for |
| 499 | * @con: connection ID for this clock |
| 500 | * |
| 501 | * Creates a clock alias for a TI clock. Allocates the clock lookup entry |
| 502 | * and assigns the data to it. Returns 0 if successful, negative error |
| 503 | * value otherwise. |
| 504 | */ |
| 505 | int ti_clk_add_alias(struct device *dev, struct clk *clk, const char *con) |
| 506 | { |
| 507 | struct clk_lookup *cl; |
| 508 | |
| 509 | if (!clk) |
| 510 | return 0; |
| 511 | |
| 512 | if (IS_ERR(clk)) |
| 513 | return PTR_ERR(clk); |
| 514 | |
| 515 | cl = kzalloc(sizeof(*cl), GFP_KERNEL); |
| 516 | if (!cl) |
| 517 | return -ENOMEM; |
| 518 | |
| 519 | if (dev) |
| 520 | cl->dev_id = dev_name(dev); |
| 521 | cl->con_id = con; |
| 522 | cl->clk = clk; |
| 523 | |
| 524 | clkdev_add(cl); |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * ti_clk_register - register a TI clock to the common clock framework |
| 531 | * @dev: device for this clock |
| 532 | * @hw: hardware clock handle |
| 533 | * @con: connection ID for this clock |
| 534 | * |
| 535 | * Registers a TI clock to the common clock framework, and adds a clock |
| 536 | * alias for it. Returns a handle to the registered clock if successful, |
| 537 | * ERR_PTR value in failure. |
| 538 | */ |
| 539 | struct clk *ti_clk_register(struct device *dev, struct clk_hw *hw, |
| 540 | const char *con) |
| 541 | { |
| 542 | struct clk *clk; |
| 543 | int ret; |
| 544 | |
| 545 | clk = clk_register(dev, hw); |
| 546 | if (IS_ERR(clk)) |
| 547 | return clk; |
| 548 | |
| 549 | ret = ti_clk_add_alias(dev, clk, con); |
| 550 | if (ret) { |
| 551 | clk_unregister(clk); |
| 552 | return ERR_PTR(ret); |
| 553 | } |
| 554 | |
| 555 | return clk; |
| 556 | } |