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