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