Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 5 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 6 | * Copyright (c) 2018, Theobroma Systems Design und Consulting GmbH |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <clk.h> |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 11 | #include <clk-uclass.h> |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 13 | #include <dm/read.h> |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 14 | #include <dt-structs.h> |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 16 | |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 17 | static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 18 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 19 | return (const struct clk_ops *)dev->driver->ops; |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 20 | } |
| 21 | |
Simon Glass | e70cc43 | 2016-01-20 19:43:02 -0700 | [diff] [blame] | 22 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 23 | # if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 24 | int clk_get_by_index_platdata(struct udevice *dev, int index, |
Simon Glass | 0d15463 | 2017-08-29 14:15:56 -0600 | [diff] [blame] | 25 | struct phandle_1_arg *cells, struct clk *clk) |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 26 | { |
| 27 | int ret; |
| 28 | |
| 29 | if (index != 0) |
| 30 | return -ENOSYS; |
| 31 | ret = uclass_get_device(UCLASS_CLK, 0, &clk->dev); |
| 32 | if (ret) |
| 33 | return ret; |
Simon Glass | bc79617 | 2017-08-29 14:15:58 -0600 | [diff] [blame] | 34 | clk->id = cells[0].arg[0]; |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | # else |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 39 | static int clk_of_xlate_default(struct clk *clk, |
Simon Glass | a4e0ef5 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 40 | struct ofnode_phandle_args *args) |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 41 | { |
| 42 | debug("%s(clk=%p)\n", __func__, clk); |
| 43 | |
| 44 | if (args->args_count > 1) { |
| 45 | debug("Invaild args_count: %d\n", args->args_count); |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | if (args->args_count) |
| 50 | clk->id = args->args[0]; |
| 51 | else |
| 52 | clk->id = 0; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Jagan Teki | 75f9831 | 2019-02-28 00:26:52 +0530 | [diff] [blame^] | 57 | static int clk_get_by_index_tail(int ret, ofnode node, |
| 58 | struct ofnode_phandle_args *args, |
| 59 | const char *list_name, int index, |
| 60 | struct clk *clk) |
| 61 | { |
| 62 | struct udevice *dev_clk; |
| 63 | const struct clk_ops *ops; |
| 64 | |
| 65 | assert(clk); |
| 66 | clk->dev = NULL; |
| 67 | if (ret) |
| 68 | goto err; |
| 69 | |
| 70 | ret = uclass_get_device_by_ofnode(UCLASS_CLK, args->node, &dev_clk); |
| 71 | if (ret) { |
| 72 | debug("%s: uclass_get_device_by_of_offset failed: err=%d\n", |
| 73 | __func__, ret); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | clk->dev = dev_clk; |
| 78 | |
| 79 | ops = clk_dev_ops(dev_clk); |
| 80 | |
| 81 | if (ops->of_xlate) |
| 82 | ret = ops->of_xlate(clk, args); |
| 83 | else |
| 84 | ret = clk_of_xlate_default(clk, args); |
| 85 | if (ret) { |
| 86 | debug("of_xlate() failed: %d\n", ret); |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | return clk_request(dev_clk, clk); |
| 91 | err: |
| 92 | debug("%s: Node '%s', property '%s', failed to request CLK index %d: %d\n", |
| 93 | __func__, ofnode_get_name(node), list_name, index, ret); |
| 94 | return ret; |
| 95 | } |
| 96 | |
Philipp Tomsich | 95f9a7e | 2018-01-08 11:18:18 +0100 | [diff] [blame] | 97 | static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name, |
| 98 | int index, struct clk *clk) |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 99 | { |
| 100 | int ret; |
Simon Glass | aa9bb09 | 2017-05-30 21:47:29 -0600 | [diff] [blame] | 101 | struct ofnode_phandle_args args; |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 102 | struct udevice *dev_clk; |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 103 | const struct clk_ops *ops; |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 104 | |
| 105 | debug("%s(dev=%p, index=%d, clk=%p)\n", __func__, dev, index, clk); |
| 106 | |
| 107 | assert(clk); |
Patrice Chotard | 82a8a66 | 2017-07-18 11:57:07 +0200 | [diff] [blame] | 108 | clk->dev = NULL; |
| 109 | |
Philipp Tomsich | 95f9a7e | 2018-01-08 11:18:18 +0100 | [diff] [blame] | 110 | ret = dev_read_phandle_with_args(dev, prop_name, "#clock-cells", 0, |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 111 | index, &args); |
Simon Glass | e70cc43 | 2016-01-20 19:43:02 -0700 | [diff] [blame] | 112 | if (ret) { |
| 113 | debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n", |
| 114 | __func__, ret); |
| 115 | return ret; |
| 116 | } |
| 117 | |
Simon Glass | aa9bb09 | 2017-05-30 21:47:29 -0600 | [diff] [blame] | 118 | ret = uclass_get_device_by_ofnode(UCLASS_CLK, args.node, &dev_clk); |
Simon Glass | e70cc43 | 2016-01-20 19:43:02 -0700 | [diff] [blame] | 119 | if (ret) { |
| 120 | debug("%s: uclass_get_device_by_of_offset failed: err=%d\n", |
| 121 | __func__, ret); |
| 122 | return ret; |
| 123 | } |
Wenyou Yang | 3f56b13 | 2016-09-27 11:00:28 +0800 | [diff] [blame] | 124 | |
| 125 | clk->dev = dev_clk; |
| 126 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 127 | ops = clk_dev_ops(dev_clk); |
| 128 | |
| 129 | if (ops->of_xlate) |
Simon Glass | aa9bb09 | 2017-05-30 21:47:29 -0600 | [diff] [blame] | 130 | ret = ops->of_xlate(clk, &args); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 131 | else |
Simon Glass | aa9bb09 | 2017-05-30 21:47:29 -0600 | [diff] [blame] | 132 | ret = clk_of_xlate_default(clk, &args); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 133 | if (ret) { |
| 134 | debug("of_xlate() failed: %d\n", ret); |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | return clk_request(dev_clk, clk); |
| 139 | } |
Philipp Tomsich | 95f9a7e | 2018-01-08 11:18:18 +0100 | [diff] [blame] | 140 | |
| 141 | int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) |
| 142 | { |
Jagan Teki | 75f9831 | 2019-02-28 00:26:52 +0530 | [diff] [blame^] | 143 | struct ofnode_phandle_args args; |
| 144 | int ret; |
| 145 | |
| 146 | ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0, |
| 147 | index, &args); |
| 148 | |
| 149 | return clk_get_by_index_tail(ret, dev_ofnode(dev), &args, "clocks", |
| 150 | index > 0, clk); |
| 151 | } |
| 152 | |
| 153 | int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk) |
| 154 | { |
| 155 | struct ofnode_phandle_args args; |
| 156 | int ret; |
| 157 | |
| 158 | ret = ofnode_parse_phandle_with_args(node, "clocks", "#clock-cells", 0, |
| 159 | index > 0, &args); |
| 160 | |
| 161 | return clk_get_by_index_tail(ret, node, &args, "clocks", |
| 162 | index > 0, clk); |
Philipp Tomsich | 95f9a7e | 2018-01-08 11:18:18 +0100 | [diff] [blame] | 163 | } |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 164 | |
Neil Armstrong | a855be8 | 2018-04-03 11:44:18 +0200 | [diff] [blame] | 165 | int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk) |
| 166 | { |
| 167 | int i, ret, err, count; |
| 168 | |
| 169 | bulk->count = 0; |
| 170 | |
| 171 | count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); |
Neil Armstrong | 721881c | 2018-04-17 11:30:31 +0200 | [diff] [blame] | 172 | if (count < 1) |
| 173 | return count; |
Neil Armstrong | a855be8 | 2018-04-03 11:44:18 +0200 | [diff] [blame] | 174 | |
| 175 | bulk->clks = devm_kcalloc(dev, count, sizeof(struct clk), GFP_KERNEL); |
| 176 | if (!bulk->clks) |
| 177 | return -ENOMEM; |
| 178 | |
| 179 | for (i = 0; i < count; i++) { |
| 180 | ret = clk_get_by_index(dev, i, &bulk->clks[i]); |
| 181 | if (ret < 0) |
| 182 | goto bulk_get_err; |
| 183 | |
| 184 | ++bulk->count; |
| 185 | } |
| 186 | |
| 187 | return 0; |
| 188 | |
| 189 | bulk_get_err: |
| 190 | err = clk_release_all(bulk->clks, bulk->count); |
| 191 | if (err) |
| 192 | debug("%s: could release all clocks for %p\n", |
| 193 | __func__, dev); |
| 194 | |
| 195 | return ret; |
| 196 | } |
| 197 | |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 198 | static int clk_set_default_parents(struct udevice *dev) |
| 199 | { |
| 200 | struct clk clk, parent_clk; |
| 201 | int index; |
| 202 | int num_parents; |
| 203 | int ret; |
| 204 | |
| 205 | num_parents = dev_count_phandle_with_args(dev, "assigned-clock-parents", |
| 206 | "#clock-cells"); |
| 207 | if (num_parents < 0) { |
| 208 | debug("%s: could not read assigned-clock-parents for %p\n", |
| 209 | __func__, dev); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | for (index = 0; index < num_parents; index++) { |
| 214 | ret = clk_get_by_indexed_prop(dev, "assigned-clock-parents", |
| 215 | index, &parent_clk); |
Neil Armstrong | d64caaf | 2018-07-26 15:19:32 +0200 | [diff] [blame] | 216 | /* If -ENOENT, this is a no-op entry */ |
| 217 | if (ret == -ENOENT) |
| 218 | continue; |
| 219 | |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 220 | if (ret) { |
| 221 | debug("%s: could not get parent clock %d for %s\n", |
| 222 | __func__, index, dev_read_name(dev)); |
| 223 | return ret; |
| 224 | } |
| 225 | |
| 226 | ret = clk_get_by_indexed_prop(dev, "assigned-clocks", |
| 227 | index, &clk); |
| 228 | if (ret) { |
| 229 | debug("%s: could not get assigned clock %d for %s\n", |
| 230 | __func__, index, dev_read_name(dev)); |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | ret = clk_set_parent(&clk, &parent_clk); |
| 235 | |
| 236 | /* |
| 237 | * Not all drivers may support clock-reparenting (as of now). |
| 238 | * Ignore errors due to this. |
| 239 | */ |
| 240 | if (ret == -ENOSYS) |
| 241 | continue; |
| 242 | |
| 243 | if (ret) { |
| 244 | debug("%s: failed to reparent clock %d for %s\n", |
| 245 | __func__, index, dev_read_name(dev)); |
| 246 | return ret; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int clk_set_default_rates(struct udevice *dev) |
| 254 | { |
| 255 | struct clk clk; |
| 256 | int index; |
| 257 | int num_rates; |
| 258 | int size; |
| 259 | int ret = 0; |
| 260 | u32 *rates = NULL; |
| 261 | |
| 262 | size = dev_read_size(dev, "assigned-clock-rates"); |
| 263 | if (size < 0) |
| 264 | return 0; |
| 265 | |
| 266 | num_rates = size / sizeof(u32); |
| 267 | rates = calloc(num_rates, sizeof(u32)); |
| 268 | if (!rates) |
| 269 | return -ENOMEM; |
| 270 | |
| 271 | ret = dev_read_u32_array(dev, "assigned-clock-rates", rates, num_rates); |
| 272 | if (ret) |
| 273 | goto fail; |
| 274 | |
| 275 | for (index = 0; index < num_rates; index++) { |
Neil Armstrong | d64caaf | 2018-07-26 15:19:32 +0200 | [diff] [blame] | 276 | /* If 0 is passed, this is a no-op */ |
| 277 | if (!rates[index]) |
| 278 | continue; |
| 279 | |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 280 | ret = clk_get_by_indexed_prop(dev, "assigned-clocks", |
| 281 | index, &clk); |
| 282 | if (ret) { |
| 283 | debug("%s: could not get assigned clock %d for %s\n", |
| 284 | __func__, index, dev_read_name(dev)); |
| 285 | continue; |
| 286 | } |
| 287 | |
| 288 | ret = clk_set_rate(&clk, rates[index]); |
| 289 | if (ret < 0) { |
Simon Glass | 6831616 | 2019-01-21 14:53:19 -0700 | [diff] [blame] | 290 | debug("%s: failed to set rate on clock index %d (%ld) for %s\n", |
| 291 | __func__, index, clk.id, dev_read_name(dev)); |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | fail: |
| 297 | free(rates); |
| 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | int clk_set_defaults(struct udevice *dev) |
| 302 | { |
| 303 | int ret; |
| 304 | |
Philipp Tomsich | 291da96 | 2018-11-26 20:20:19 +0100 | [diff] [blame] | 305 | /* If this not in SPL and pre-reloc state, don't take any action. */ |
| 306 | if (!(IS_ENABLED(CONFIG_SPL_BUILD) || (gd->flags & GD_FLG_RELOC))) |
| 307 | return 0; |
| 308 | |
Philipp Tomsich | f4fcba5 | 2018-01-08 13:59:18 +0100 | [diff] [blame] | 309 | debug("%s(%s)\n", __func__, dev_read_name(dev)); |
| 310 | |
| 311 | ret = clk_set_default_parents(dev); |
| 312 | if (ret) |
| 313 | return ret; |
| 314 | |
| 315 | ret = clk_set_default_rates(dev); |
| 316 | if (ret < 0) |
| 317 | return ret; |
| 318 | |
| 319 | return 0; |
| 320 | } |
Michal Simek | 9e0758b | 2016-07-14 13:11:37 +0200 | [diff] [blame] | 321 | # endif /* OF_PLATDATA */ |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 322 | |
| 323 | int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk) |
| 324 | { |
| 325 | int index; |
| 326 | |
| 327 | debug("%s(dev=%p, name=%s, clk=%p)\n", __func__, dev, name, clk); |
Patrice Chotard | 82a8a66 | 2017-07-18 11:57:07 +0200 | [diff] [blame] | 328 | clk->dev = NULL; |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 329 | |
Simon Glass | aa9bb09 | 2017-05-30 21:47:29 -0600 | [diff] [blame] | 330 | index = dev_read_stringlist_search(dev, "clock-names", name); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 331 | if (index < 0) { |
Simon Glass | b02e404 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 332 | debug("fdt_stringlist_search() failed: %d\n", index); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 333 | return index; |
| 334 | } |
| 335 | |
| 336 | return clk_get_by_index(dev, index, clk); |
Simon Glass | e70cc43 | 2016-01-20 19:43:02 -0700 | [diff] [blame] | 337 | } |
Patrice Chotard | b108d8a | 2017-07-25 13:24:45 +0200 | [diff] [blame] | 338 | |
| 339 | int clk_release_all(struct clk *clk, int count) |
| 340 | { |
| 341 | int i, ret; |
| 342 | |
| 343 | for (i = 0; i < count; i++) { |
| 344 | debug("%s(clk[%d]=%p)\n", __func__, i, &clk[i]); |
| 345 | |
| 346 | /* check if clock has been previously requested */ |
| 347 | if (!clk[i].dev) |
| 348 | continue; |
| 349 | |
| 350 | ret = clk_disable(&clk[i]); |
| 351 | if (ret && ret != -ENOSYS) |
| 352 | return ret; |
| 353 | |
| 354 | ret = clk_free(&clk[i]); |
| 355 | if (ret && ret != -ENOSYS) |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
Simon Glass | 7423daa | 2016-07-04 11:58:03 -0600 | [diff] [blame] | 362 | #endif /* OF_CONTROL */ |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 363 | |
| 364 | int clk_request(struct udevice *dev, struct clk *clk) |
| 365 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 366 | const struct clk_ops *ops = clk_dev_ops(dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 367 | |
| 368 | debug("%s(dev=%p, clk=%p)\n", __func__, dev, clk); |
| 369 | |
| 370 | clk->dev = dev; |
| 371 | |
| 372 | if (!ops->request) |
| 373 | return 0; |
| 374 | |
| 375 | return ops->request(clk); |
| 376 | } |
| 377 | |
| 378 | int clk_free(struct clk *clk) |
| 379 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 380 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 381 | |
| 382 | debug("%s(clk=%p)\n", __func__, clk); |
| 383 | |
| 384 | if (!ops->free) |
| 385 | return 0; |
| 386 | |
| 387 | return ops->free(clk); |
| 388 | } |
| 389 | |
| 390 | ulong clk_get_rate(struct clk *clk) |
| 391 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 392 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 393 | |
| 394 | debug("%s(clk=%p)\n", __func__, clk); |
| 395 | |
| 396 | if (!ops->get_rate) |
| 397 | return -ENOSYS; |
| 398 | |
| 399 | return ops->get_rate(clk); |
| 400 | } |
| 401 | |
| 402 | ulong clk_set_rate(struct clk *clk, ulong rate) |
| 403 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 404 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 405 | |
| 406 | debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate); |
| 407 | |
| 408 | if (!ops->set_rate) |
| 409 | return -ENOSYS; |
| 410 | |
| 411 | return ops->set_rate(clk, rate); |
| 412 | } |
| 413 | |
Philipp Tomsich | f7d1046 | 2018-01-08 11:15:08 +0100 | [diff] [blame] | 414 | int clk_set_parent(struct clk *clk, struct clk *parent) |
| 415 | { |
| 416 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
| 417 | |
| 418 | debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent); |
| 419 | |
| 420 | if (!ops->set_parent) |
| 421 | return -ENOSYS; |
| 422 | |
| 423 | return ops->set_parent(clk, parent); |
| 424 | } |
| 425 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 426 | int clk_enable(struct clk *clk) |
| 427 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 428 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 429 | |
| 430 | debug("%s(clk=%p)\n", __func__, clk); |
| 431 | |
| 432 | if (!ops->enable) |
| 433 | return -ENOSYS; |
| 434 | |
| 435 | return ops->enable(clk); |
| 436 | } |
| 437 | |
Neil Armstrong | a855be8 | 2018-04-03 11:44:18 +0200 | [diff] [blame] | 438 | int clk_enable_bulk(struct clk_bulk *bulk) |
| 439 | { |
| 440 | int i, ret; |
| 441 | |
| 442 | for (i = 0; i < bulk->count; i++) { |
| 443 | ret = clk_enable(&bulk->clks[i]); |
| 444 | if (ret < 0 && ret != -ENOSYS) |
| 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 451 | int clk_disable(struct clk *clk) |
| 452 | { |
Mario Six | 268453b | 2018-01-15 11:06:51 +0100 | [diff] [blame] | 453 | const struct clk_ops *ops = clk_dev_ops(clk->dev); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 454 | |
| 455 | debug("%s(clk=%p)\n", __func__, clk); |
| 456 | |
| 457 | if (!ops->disable) |
| 458 | return -ENOSYS; |
| 459 | |
| 460 | return ops->disable(clk); |
| 461 | } |
Simon Glass | e70cc43 | 2016-01-20 19:43:02 -0700 | [diff] [blame] | 462 | |
Neil Armstrong | a855be8 | 2018-04-03 11:44:18 +0200 | [diff] [blame] | 463 | int clk_disable_bulk(struct clk_bulk *bulk) |
| 464 | { |
| 465 | int i, ret; |
| 466 | |
| 467 | for (i = 0; i < bulk->count; i++) { |
| 468 | ret = clk_disable(&bulk->clks[i]); |
| 469 | if (ret < 0 && ret != -ENOSYS) |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
Simon Glass | f26c8a8 | 2015-06-23 15:39:15 -0600 | [diff] [blame] | 476 | UCLASS_DRIVER(clk) = { |
| 477 | .id = UCLASS_CLK, |
| 478 | .name = "clk", |
| 479 | }; |