Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. |
| 3 | * Copyright (c) 2013 Linaro Ltd. |
| 4 | * Author: Thomas Abraham <thomas.ab@samsung.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This file includes utility functions to register clocks to common |
| 11 | * clock framework for Samsung platforms. |
| 12 | */ |
| 13 | |
Pankaj Dubey | 8b2f636 | 2014-09-29 13:17:48 +0530 | [diff] [blame] | 14 | #include <linux/of_address.h> |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 15 | #include <linux/syscore_ops.h> |
Pankaj Dubey | 8b2f636 | 2014-09-29 13:17:48 +0530 | [diff] [blame] | 16 | |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 17 | #include "clk.h" |
| 18 | |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 19 | static LIST_HEAD(clock_reg_cache_list); |
| 20 | |
Tomasz Figa | 3ccefbd | 2014-02-14 08:16:00 +0900 | [diff] [blame] | 21 | void samsung_clk_save(void __iomem *base, |
| 22 | struct samsung_clk_reg_dump *rd, |
| 23 | unsigned int num_regs) |
| 24 | { |
| 25 | for (; num_regs > 0; --num_regs, ++rd) |
| 26 | rd->value = readl(base + rd->offset); |
| 27 | } |
| 28 | |
| 29 | void samsung_clk_restore(void __iomem *base, |
| 30 | const struct samsung_clk_reg_dump *rd, |
| 31 | unsigned int num_regs) |
| 32 | { |
| 33 | for (; num_regs > 0; --num_regs, ++rd) |
| 34 | writel(rd->value, base + rd->offset); |
| 35 | } |
| 36 | |
Tomasz Figa | c3b6c1d | 2014-02-14 08:16:00 +0900 | [diff] [blame] | 37 | struct samsung_clk_reg_dump *samsung_clk_alloc_reg_dump( |
| 38 | const unsigned long *rdump, |
| 39 | unsigned long nr_rdump) |
Tomasz Figa | 3ccefbd | 2014-02-14 08:16:00 +0900 | [diff] [blame] | 40 | { |
| 41 | struct samsung_clk_reg_dump *rd; |
| 42 | unsigned int i; |
| 43 | |
| 44 | rd = kcalloc(nr_rdump, sizeof(*rd), GFP_KERNEL); |
| 45 | if (!rd) |
| 46 | return NULL; |
| 47 | |
| 48 | for (i = 0; i < nr_rdump; ++i) |
| 49 | rd[i].offset = rdump[i]; |
| 50 | |
| 51 | return rd; |
| 52 | } |
| 53 | |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 54 | /* setup the essentials required to support clock lookup using ccf */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 55 | struct samsung_clk_provider *__init samsung_clk_init(struct device_node *np, |
| 56 | void __iomem *base, unsigned long nr_clks) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 57 | { |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 58 | struct samsung_clk_provider *ctx; |
| 59 | struct clk **clk_table; |
Tomasz Figa | 91a1263 | 2014-02-06 19:33:11 +0100 | [diff] [blame] | 60 | int i; |
| 61 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 62 | ctx = kzalloc(sizeof(struct samsung_clk_provider), GFP_KERNEL); |
| 63 | if (!ctx) |
| 64 | panic("could not allocate clock provider context.\n"); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 65 | |
Tomasz Figa | 91a1263 | 2014-02-06 19:33:11 +0100 | [diff] [blame] | 66 | clk_table = kcalloc(nr_clks, sizeof(struct clk *), GFP_KERNEL); |
Heiko Stueber | 2466196 | 2013-03-18 13:43:52 +0900 | [diff] [blame] | 67 | if (!clk_table) |
| 68 | panic("could not allocate clock lookup table\n"); |
| 69 | |
Tomasz Figa | 91a1263 | 2014-02-06 19:33:11 +0100 | [diff] [blame] | 70 | for (i = 0; i < nr_clks; ++i) |
| 71 | clk_table[i] = ERR_PTR(-ENOENT); |
| 72 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 73 | ctx->reg_base = base; |
| 74 | ctx->clk_data.clks = clk_table; |
| 75 | ctx->clk_data.clk_num = nr_clks; |
| 76 | spin_lock_init(&ctx->lock); |
Heiko Stuebner | 6e92bf5a | 2013-03-18 13:43:52 +0900 | [diff] [blame] | 77 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 78 | return ctx; |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 79 | } |
| 80 | |
Sylwester Nawrocki | d5e136a | 2014-06-18 17:46:52 +0200 | [diff] [blame] | 81 | void __init samsung_clk_of_add_provider(struct device_node *np, |
| 82 | struct samsung_clk_provider *ctx) |
| 83 | { |
| 84 | if (np) { |
| 85 | if (of_clk_add_provider(np, of_clk_src_onecell_get, |
| 86 | &ctx->clk_data)) |
| 87 | panic("could not register clk provider\n"); |
| 88 | } |
| 89 | } |
| 90 | |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 91 | /* add a clock instance to the clock lookup table used for dt based lookup */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 92 | void samsung_clk_add_lookup(struct samsung_clk_provider *ctx, struct clk *clk, |
| 93 | unsigned int id) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 94 | { |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 95 | if (ctx->clk_data.clks && id) |
| 96 | ctx->clk_data.clks[id] = clk; |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 97 | } |
| 98 | |
Heiko Stuebner | 5e2e019 | 2013-03-18 13:43:56 +0900 | [diff] [blame] | 99 | /* register a list of aliases */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 100 | void __init samsung_clk_register_alias(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 101 | const struct samsung_clock_alias *list, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 102 | unsigned int nr_clk) |
Heiko Stuebner | 5e2e019 | 2013-03-18 13:43:56 +0900 | [diff] [blame] | 103 | { |
| 104 | struct clk *clk; |
| 105 | unsigned int idx, ret; |
| 106 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 107 | if (!ctx->clk_data.clks) { |
Heiko Stuebner | 5e2e019 | 2013-03-18 13:43:56 +0900 | [diff] [blame] | 108 | pr_err("%s: clock table missing\n", __func__); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | for (idx = 0; idx < nr_clk; idx++, list++) { |
| 113 | if (!list->id) { |
| 114 | pr_err("%s: clock id missing for index %d\n", __func__, |
| 115 | idx); |
| 116 | continue; |
| 117 | } |
| 118 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 119 | clk = ctx->clk_data.clks[list->id]; |
Heiko Stuebner | 5e2e019 | 2013-03-18 13:43:56 +0900 | [diff] [blame] | 120 | if (!clk) { |
| 121 | pr_err("%s: failed to find clock %d\n", __func__, |
| 122 | list->id); |
| 123 | continue; |
| 124 | } |
| 125 | |
| 126 | ret = clk_register_clkdev(clk, list->alias, list->dev_name); |
| 127 | if (ret) |
| 128 | pr_err("%s: failed to register lookup %s\n", |
| 129 | __func__, list->alias); |
| 130 | } |
| 131 | } |
| 132 | |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 133 | /* register a list of fixed clocks */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 134 | void __init samsung_clk_register_fixed_rate(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 135 | const struct samsung_fixed_rate_clock *list, |
| 136 | unsigned int nr_clk) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 137 | { |
| 138 | struct clk *clk; |
| 139 | unsigned int idx, ret; |
| 140 | |
| 141 | for (idx = 0; idx < nr_clk; idx++, list++) { |
| 142 | clk = clk_register_fixed_rate(NULL, list->name, |
| 143 | list->parent_name, list->flags, list->fixed_rate); |
| 144 | if (IS_ERR(clk)) { |
| 145 | pr_err("%s: failed to register clock %s\n", __func__, |
| 146 | list->name); |
| 147 | continue; |
| 148 | } |
| 149 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 150 | samsung_clk_add_lookup(ctx, clk, list->id); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Unconditionally add a clock lookup for the fixed rate clocks. |
| 154 | * There are not many of these on any of Samsung platforms. |
| 155 | */ |
| 156 | ret = clk_register_clkdev(clk, list->name, NULL); |
| 157 | if (ret) |
| 158 | pr_err("%s: failed to register clock lookup for %s", |
| 159 | __func__, list->name); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* register a list of fixed factor clocks */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 164 | void __init samsung_clk_register_fixed_factor(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 165 | const struct samsung_fixed_factor_clock *list, unsigned int nr_clk) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 166 | { |
| 167 | struct clk *clk; |
| 168 | unsigned int idx; |
| 169 | |
| 170 | for (idx = 0; idx < nr_clk; idx++, list++) { |
| 171 | clk = clk_register_fixed_factor(NULL, list->name, |
| 172 | list->parent_name, list->flags, list->mult, list->div); |
| 173 | if (IS_ERR(clk)) { |
| 174 | pr_err("%s: failed to register clock %s\n", __func__, |
| 175 | list->name); |
| 176 | continue; |
| 177 | } |
| 178 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 179 | samsung_clk_add_lookup(ctx, clk, list->id); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | /* register a list of mux clocks */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 184 | void __init samsung_clk_register_mux(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 185 | const struct samsung_mux_clock *list, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 186 | unsigned int nr_clk) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 187 | { |
| 188 | struct clk *clk; |
| 189 | unsigned int idx, ret; |
| 190 | |
| 191 | for (idx = 0; idx < nr_clk; idx++, list++) { |
| 192 | clk = clk_register_mux(NULL, list->name, list->parent_names, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 193 | list->num_parents, list->flags, |
| 194 | ctx->reg_base + list->offset, |
| 195 | list->shift, list->width, list->mux_flags, &ctx->lock); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 196 | if (IS_ERR(clk)) { |
| 197 | pr_err("%s: failed to register clock %s\n", __func__, |
| 198 | list->name); |
| 199 | continue; |
| 200 | } |
| 201 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 202 | samsung_clk_add_lookup(ctx, clk, list->id); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 203 | |
| 204 | /* register a clock lookup only if a clock alias is specified */ |
| 205 | if (list->alias) { |
| 206 | ret = clk_register_clkdev(clk, list->alias, |
| 207 | list->dev_name); |
| 208 | if (ret) |
| 209 | pr_err("%s: failed to register lookup %s\n", |
| 210 | __func__, list->alias); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /* register a list of div clocks */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 216 | void __init samsung_clk_register_div(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 217 | const struct samsung_div_clock *list, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 218 | unsigned int nr_clk) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 219 | { |
| 220 | struct clk *clk; |
| 221 | unsigned int idx, ret; |
| 222 | |
| 223 | for (idx = 0; idx < nr_clk; idx++, list++) { |
Heiko Stuebner | 798ed61 | 2013-03-18 13:43:52 +0900 | [diff] [blame] | 224 | if (list->table) |
| 225 | clk = clk_register_divider_table(NULL, list->name, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 226 | list->parent_name, list->flags, |
| 227 | ctx->reg_base + list->offset, |
| 228 | list->shift, list->width, list->div_flags, |
| 229 | list->table, &ctx->lock); |
Heiko Stuebner | 798ed61 | 2013-03-18 13:43:52 +0900 | [diff] [blame] | 230 | else |
| 231 | clk = clk_register_divider(NULL, list->name, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 232 | list->parent_name, list->flags, |
| 233 | ctx->reg_base + list->offset, list->shift, |
| 234 | list->width, list->div_flags, &ctx->lock); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 235 | if (IS_ERR(clk)) { |
| 236 | pr_err("%s: failed to register clock %s\n", __func__, |
| 237 | list->name); |
| 238 | continue; |
| 239 | } |
| 240 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 241 | samsung_clk_add_lookup(ctx, clk, list->id); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 242 | |
| 243 | /* register a clock lookup only if a clock alias is specified */ |
| 244 | if (list->alias) { |
| 245 | ret = clk_register_clkdev(clk, list->alias, |
| 246 | list->dev_name); |
| 247 | if (ret) |
| 248 | pr_err("%s: failed to register lookup %s\n", |
| 249 | __func__, list->alias); |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /* register a list of gate clocks */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 255 | void __init samsung_clk_register_gate(struct samsung_clk_provider *ctx, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 256 | const struct samsung_gate_clock *list, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 257 | unsigned int nr_clk) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 258 | { |
| 259 | struct clk *clk; |
| 260 | unsigned int idx, ret; |
| 261 | |
| 262 | for (idx = 0; idx < nr_clk; idx++, list++) { |
| 263 | clk = clk_register_gate(NULL, list->name, list->parent_name, |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 264 | list->flags, ctx->reg_base + list->offset, |
| 265 | list->bit_idx, list->gate_flags, &ctx->lock); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 266 | if (IS_ERR(clk)) { |
| 267 | pr_err("%s: failed to register clock %s\n", __func__, |
| 268 | list->name); |
| 269 | continue; |
| 270 | } |
| 271 | |
| 272 | /* register a clock lookup only if a clock alias is specified */ |
| 273 | if (list->alias) { |
| 274 | ret = clk_register_clkdev(clk, list->alias, |
| 275 | list->dev_name); |
| 276 | if (ret) |
| 277 | pr_err("%s: failed to register lookup %s\n", |
| 278 | __func__, list->alias); |
| 279 | } |
| 280 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 281 | samsung_clk_add_lookup(ctx, clk, list->id); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * obtain the clock speed of all external fixed clock sources from device |
| 287 | * tree and register it |
| 288 | */ |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 289 | void __init samsung_clk_of_register_fixed_ext(struct samsung_clk_provider *ctx, |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 290 | struct samsung_fixed_rate_clock *fixed_rate_clk, |
| 291 | unsigned int nr_fixed_rate_clk, |
Krzysztof Kozlowski | 305cfab | 2014-06-26 14:00:06 +0200 | [diff] [blame] | 292 | const struct of_device_id *clk_matches) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 293 | { |
| 294 | const struct of_device_id *match; |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 295 | struct device_node *clk_np; |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 296 | u32 freq; |
| 297 | |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 298 | for_each_matching_node_and_match(clk_np, clk_matches, &match) { |
| 299 | if (of_property_read_u32(clk_np, "clock-frequency", &freq)) |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 300 | continue; |
Pankaj Dubey | 42fb57c | 2014-02-26 11:42:41 +0900 | [diff] [blame] | 301 | fixed_rate_clk[(unsigned long)match->data].fixed_rate = freq; |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 302 | } |
Rahul Sharma | 976face | 2014-03-12 20:26:44 +0530 | [diff] [blame] | 303 | samsung_clk_register_fixed_rate(ctx, fixed_rate_clk, nr_fixed_rate_clk); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 304 | } |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 305 | |
| 306 | /* utility function to get the rate of a specified clock */ |
| 307 | unsigned long _get_rate(const char *clk_name) |
| 308 | { |
| 309 | struct clk *clk; |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 310 | |
Tomasz Figa | 3a64789 | 2013-08-26 19:09:00 +0200 | [diff] [blame] | 311 | clk = __clk_lookup(clk_name); |
| 312 | if (!clk) { |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 313 | pr_err("%s: could not find clock %s\n", __func__, clk_name); |
| 314 | return 0; |
| 315 | } |
Tomasz Figa | 3a64789 | 2013-08-26 19:09:00 +0200 | [diff] [blame] | 316 | |
| 317 | return clk_get_rate(clk); |
Thomas Abraham | 721c42a | 2013-03-09 17:02:44 +0900 | [diff] [blame] | 318 | } |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 319 | |
| 320 | #ifdef CONFIG_PM_SLEEP |
| 321 | static int samsung_clk_suspend(void) |
| 322 | { |
| 323 | struct samsung_clock_reg_cache *reg_cache; |
| 324 | |
| 325 | list_for_each_entry(reg_cache, &clock_reg_cache_list, node) |
| 326 | samsung_clk_save(reg_cache->reg_base, reg_cache->rdump, |
| 327 | reg_cache->rd_num); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static void samsung_clk_resume(void) |
| 332 | { |
| 333 | struct samsung_clock_reg_cache *reg_cache; |
| 334 | |
| 335 | list_for_each_entry(reg_cache, &clock_reg_cache_list, node) |
| 336 | samsung_clk_restore(reg_cache->reg_base, reg_cache->rdump, |
| 337 | reg_cache->rd_num); |
| 338 | } |
| 339 | |
| 340 | static struct syscore_ops samsung_clk_syscore_ops = { |
| 341 | .suspend = samsung_clk_suspend, |
| 342 | .resume = samsung_clk_resume, |
| 343 | }; |
| 344 | |
| 345 | static void samsung_clk_sleep_init(void __iomem *reg_base, |
| 346 | const unsigned long *rdump, |
| 347 | unsigned long nr_rdump) |
| 348 | { |
| 349 | struct samsung_clock_reg_cache *reg_cache; |
| 350 | |
| 351 | reg_cache = kzalloc(sizeof(struct samsung_clock_reg_cache), |
| 352 | GFP_KERNEL); |
| 353 | if (!reg_cache) |
| 354 | panic("could not allocate register reg_cache.\n"); |
| 355 | reg_cache->rdump = samsung_clk_alloc_reg_dump(rdump, nr_rdump); |
| 356 | |
| 357 | if (!reg_cache->rdump) |
| 358 | panic("could not allocate register dump storage.\n"); |
| 359 | |
| 360 | if (list_empty(&clock_reg_cache_list)) |
| 361 | register_syscore_ops(&samsung_clk_syscore_ops); |
| 362 | |
| 363 | reg_cache->reg_base = reg_base; |
| 364 | reg_cache->rd_num = nr_rdump; |
| 365 | list_add_tail(®_cache->node, &clock_reg_cache_list); |
| 366 | } |
| 367 | |
| 368 | #else |
| 369 | static void samsung_clk_sleep_init(void __iomem *reg_base, |
| 370 | const unsigned long *rdump, |
| 371 | unsigned long nr_rdump) {} |
| 372 | #endif |
| 373 | |
| 374 | /* |
| 375 | * Common function which registers plls, muxes, dividers and gates |
| 376 | * for each CMU. It also add CMU register list to register cache. |
| 377 | */ |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 378 | struct samsung_clk_provider * __init samsung_cmu_register_one( |
| 379 | struct device_node *np, |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 380 | struct samsung_cmu_info *cmu) |
| 381 | { |
| 382 | void __iomem *reg_base; |
| 383 | struct samsung_clk_provider *ctx; |
| 384 | |
| 385 | reg_base = of_iomap(np, 0); |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 386 | if (!reg_base) { |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 387 | panic("%s: failed to map registers\n", __func__); |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 388 | return NULL; |
| 389 | } |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 390 | |
| 391 | ctx = samsung_clk_init(np, reg_base, cmu->nr_clk_ids); |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 392 | if (!ctx) { |
Shailendra Verma | c306317 | 2015-05-21 23:26:03 +0530 | [diff] [blame] | 393 | panic("%s: unable to allocate ctx\n", __func__); |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 394 | return ctx; |
| 395 | } |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 396 | |
| 397 | if (cmu->pll_clks) |
| 398 | samsung_clk_register_pll(ctx, cmu->pll_clks, cmu->nr_pll_clks, |
| 399 | reg_base); |
| 400 | if (cmu->mux_clks) |
| 401 | samsung_clk_register_mux(ctx, cmu->mux_clks, |
| 402 | cmu->nr_mux_clks); |
| 403 | if (cmu->div_clks) |
| 404 | samsung_clk_register_div(ctx, cmu->div_clks, cmu->nr_div_clks); |
| 405 | if (cmu->gate_clks) |
| 406 | samsung_clk_register_gate(ctx, cmu->gate_clks, |
| 407 | cmu->nr_gate_clks); |
| 408 | if (cmu->fixed_clks) |
| 409 | samsung_clk_register_fixed_rate(ctx, cmu->fixed_clks, |
| 410 | cmu->nr_fixed_clks); |
Naveen Krishna Ch | 0e5af27 | 2014-09-22 10:17:03 +0530 | [diff] [blame] | 411 | if (cmu->fixed_factor_clks) |
| 412 | samsung_clk_register_fixed_factor(ctx, cmu->fixed_factor_clks, |
| 413 | cmu->nr_fixed_factor_clks); |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 414 | if (cmu->clk_regs) |
| 415 | samsung_clk_sleep_init(reg_base, cmu->clk_regs, |
| 416 | cmu->nr_clk_regs); |
| 417 | |
| 418 | samsung_clk_of_add_provider(np, ctx); |
Chanwoo Choi | 151d4d3 | 2014-12-23 16:40:21 +0900 | [diff] [blame] | 419 | |
| 420 | return ctx; |
Naveen Krishna Ch | 16a9013 | 2014-09-22 10:17:02 +0530 | [diff] [blame] | 421 | } |