1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Arm Ltd
4 * Author: Liviu Dudau <liviu.dudau@foss.arm.com>
9 #include <clk-uclass.h>
15 #define CLK_FUNCTION BIT(20)
17 struct vexpress_osc_clk_priv {
23 static ulong vexpress_osc_clk_get_rate(struct clk *clk)
27 struct udevice *vexpress_cfg = dev_get_parent(clk->dev);
28 struct vexpress_osc_clk_priv *priv = dev_get_priv(clk->dev);
30 data = CLK_FUNCTION | priv->osc;
31 err = misc_read(vexpress_cfg, 0, &data, sizeof(data));
38 #ifndef CONFIG_SPL_BUILD
39 static ulong vexpress_osc_clk_set_rate(struct clk *clk, ulong rate)
43 struct udevice *vexpress_cfg = dev_get_parent(clk->dev);
44 struct vexpress_osc_clk_priv *priv = dev_get_priv(clk->dev);
46 if (rate < priv->rate_min || rate > priv->rate_max)
50 * we are sending the parent the info about the oscillator
51 * and the value we want to set
53 buffer[0] = CLK_FUNCTION | priv->osc;
55 err = misc_write(vexpress_cfg, 0, buffer, 2 * sizeof(u32));
63 static struct clk_ops vexpress_osc_clk_ops = {
64 .get_rate = vexpress_osc_clk_get_rate,
65 #ifndef CONFIG_SPL_BUILD
66 .set_rate = vexpress_osc_clk_set_rate,
70 static int vexpress_osc_clk_probe(struct udevice *dev)
72 struct vexpress_osc_clk_priv *priv = dev_get_priv(dev);
76 err = dev_read_u32_array(dev, "freq-range", values, 2);
79 priv->rate_min = values[0];
80 priv->rate_max = values[1];
82 err = dev_read_u32_array(dev, "arm,vexpress-sysreg,func", values, 2);
87 dev_err(dev, "Invalid VExpress function for clock, must be '1'");
90 priv->osc = values[1];
91 debug("clk \"%s%d\", min freq %luHz, max freq %luHz\n", dev->name,
92 priv->osc, priv->rate_min, priv->rate_max);
97 static const struct udevice_id vexpress_osc_clk_ids[] = {
98 { .compatible = "arm,vexpress-osc", },
102 U_BOOT_DRIVER(vexpress_osc_clk) = {
103 .name = "vexpress_osc_clk",
105 .of_match = vexpress_osc_clk_ids,
106 .ops = &vexpress_osc_clk_ops,
107 .priv_auto_alloc_size = sizeof(struct vexpress_osc_clk_priv),
108 .probe = vexpress_osc_clk_probe,