1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016 Imagination Technologies
7 #include <clk-uclass.h>
9 #include <dt-bindings/clock/boston-clock.h>
14 struct regmap *regmap;
17 #define BOSTON_PLAT_MMCMDIV 0x30
18 # define BOSTON_PLAT_MMCMDIV_CLK0DIV (0xff << 0)
19 # define BOSTON_PLAT_MMCMDIV_INPUT (0xff << 8)
20 # define BOSTON_PLAT_MMCMDIV_MUL (0xff << 16)
21 # define BOSTON_PLAT_MMCMDIV_CLK1DIV (0xff << 24)
23 static uint32_t ext_field(uint32_t val, uint32_t mask)
25 return (val & mask) >> (ffs(mask) - 1);
28 static ulong clk_boston_get_rate(struct clk *clk)
30 struct clk_boston *state = dev_get_platdata(clk->dev);
31 uint32_t in_rate, mul, div;
35 err = regmap_read(state->regmap, BOSTON_PLAT_MMCMDIV, &mmcmdiv);
39 in_rate = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_INPUT);
40 mul = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_MUL);
44 div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK0DIV);
47 div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK1DIV);
53 return (in_rate * mul * 1000000) / div;
56 const struct clk_ops clk_boston_ops = {
57 .get_rate = clk_boston_get_rate,
60 static int clk_boston_ofdata_to_platdata(struct udevice *dev)
62 struct clk_boston *state = dev_get_platdata(dev);
63 struct udevice *syscon;
66 err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
69 pr_err("unable to find syscon device\n");
73 state->regmap = syscon_get_regmap(syscon);
75 pr_err("unable to find regmap\n");
82 static const struct udevice_id clk_boston_match[] = {
84 .compatible = "img,boston-clock",
89 U_BOOT_DRIVER(clk_boston) = {
90 .name = "boston_clock",
92 .of_match = clk_boston_match,
93 .ofdata_to_platdata = clk_boston_ofdata_to_platdata,
94 .platdata_auto_alloc_size = sizeof(struct clk_boston),
95 .ops = &clk_boston_ops,