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>
12 #include <dm/device_compat.h>
16 #include <linux/bitops.h>
18 #define CLK_FUNCTION BIT(20)
20 struct vexpress_osc_clk_priv {
26 static ulong vexpress_osc_clk_get_rate(struct clk *clk)
30 struct udevice *vexpress_cfg = dev_get_parent(clk->dev);
31 struct vexpress_osc_clk_priv *priv = dev_get_priv(clk->dev);
33 data = CLK_FUNCTION | priv->osc;
34 err = misc_read(vexpress_cfg, 0, &data, sizeof(data));
41 #ifndef CONFIG_SPL_BUILD
42 static ulong vexpress_osc_clk_set_rate(struct clk *clk, ulong rate)
46 struct udevice *vexpress_cfg = dev_get_parent(clk->dev);
47 struct vexpress_osc_clk_priv *priv = dev_get_priv(clk->dev);
49 if (rate < priv->rate_min || rate > priv->rate_max)
53 * we are sending the parent the info about the oscillator
54 * and the value we want to set
56 buffer[0] = CLK_FUNCTION | priv->osc;
58 err = misc_write(vexpress_cfg, 0, buffer, 2 * sizeof(u32));
66 static struct clk_ops vexpress_osc_clk_ops = {
67 .get_rate = vexpress_osc_clk_get_rate,
68 #ifndef CONFIG_SPL_BUILD
69 .set_rate = vexpress_osc_clk_set_rate,
73 static int vexpress_osc_clk_probe(struct udevice *dev)
75 struct vexpress_osc_clk_priv *priv = dev_get_priv(dev);
79 err = dev_read_u32_array(dev, "freq-range", values, 2);
82 priv->rate_min = values[0];
83 priv->rate_max = values[1];
85 err = dev_read_u32_array(dev, "arm,vexpress-sysreg,func", values, 2);
90 dev_err(dev, "Invalid VExpress function for clock, must be '1'");
93 priv->osc = values[1];
94 debug("clk \"%s%d\", min freq %luHz, max freq %luHz\n", dev->name,
95 priv->osc, priv->rate_min, priv->rate_max);
100 static const struct udevice_id vexpress_osc_clk_ids[] = {
101 { .compatible = "arm,vexpress-osc", },
105 U_BOOT_DRIVER(vexpress_osc_clk) = {
106 .name = "vexpress_osc_clk",
108 .of_match = vexpress_osc_clk_ids,
109 .ops = &vexpress_osc_clk_ops,
110 .priv_auto = sizeof(struct vexpress_osc_clk_priv),
111 .probe = vexpress_osc_clk_probe,