2 * Copyright (C) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
15 DECLARE_GLOBAL_DATA_PTR;
17 ulong clk_get_rate(struct udevice *dev)
19 struct clk_ops *ops = clk_get_ops(dev);
24 return ops->get_rate(dev);
27 ulong clk_set_rate(struct udevice *dev, ulong rate)
29 struct clk_ops *ops = clk_get_ops(dev);
34 return ops->set_rate(dev, rate);
37 int clk_enable(struct udevice *dev, int periph)
39 struct clk_ops *ops = clk_get_ops(dev);
44 return ops->enable(dev, periph);
47 ulong clk_get_periph_rate(struct udevice *dev, int periph)
49 struct clk_ops *ops = clk_get_ops(dev);
51 if (!ops->get_periph_rate)
54 return ops->get_periph_rate(dev, periph);
57 ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate)
59 struct clk_ops *ops = clk_get_ops(dev);
61 if (!ops->set_periph_rate)
64 return ops->set_periph_rate(dev, periph, rate);
67 #if CONFIG_IS_ENABLED(OF_CONTROL)
68 int clk_get_by_index(struct udevice *dev, int index, struct udevice **clk_devp)
71 #ifdef CONFIG_SPL_BUILD
77 ret = uclass_get_device(UCLASS_CLK, 0, clk_devp);
80 ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, "clocks",
86 struct fdtdec_phandle_args args;
89 ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev->of_offset,
90 "clocks", "#clock-cells", 0, index,
93 debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n",
98 ret = uclass_get_device_by_of_offset(UCLASS_CLK, args.node, clk_devp);
100 debug("%s: uclass_get_device_by_of_offset failed: err=%d\n",
104 return args.args_count > 0 ? args.args[0] : 0;
109 UCLASS_DRIVER(clk) = {