1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2019 Western Digital Corporation or its affiliates.
5 * Author: Anup Patel <anup.patel@wdc.com>
9 #include <clk-uclass.h>
12 #include <linux/err.h>
14 struct clk_fixed_factor {
20 #define to_clk_fixed_factor(dev) \
21 ((struct clk_fixed_factor *)dev_get_plat(dev))
23 static ulong clk_fixed_factor_get_rate(struct clk *clk)
26 struct clk_fixed_factor *ff = to_clk_fixed_factor(clk->dev);
28 rate = clk_get_rate(&ff->parent);
29 if (IS_ERR_VALUE(rate))
32 do_div(rate, ff->div);
34 return rate * ff->mult;
37 const struct clk_ops clk_fixed_factor_ops = {
38 .get_rate = clk_fixed_factor_get_rate,
41 static int clk_fixed_factor_of_to_plat(struct udevice *dev)
43 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
45 struct clk_fixed_factor *ff = to_clk_fixed_factor(dev);
47 err = clk_get_by_index(dev, 0, &ff->parent);
51 ff->div = dev_read_u32_default(dev, "clock-div", 1);
52 ff->mult = dev_read_u32_default(dev, "clock-mult", 1);
58 static const struct udevice_id clk_fixed_factor_match[] = {
60 .compatible = "fixed-factor-clock",
65 U_BOOT_DRIVER(clk_fixed_factor) = {
66 .name = "fixed_factor_clock",
68 .of_match = clk_fixed_factor_match,
69 .of_to_plat = clk_fixed_factor_of_to_plat,
70 .plat_auto = sizeof(struct clk_fixed_factor),
71 .ops = &clk_fixed_factor_ops,