1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
5 */
6
7 #include <common.h>
8 #include <clk-uclass.h>
9 #include <dm/device.h>
10 #include <dm/uclass.h>
11 #include <dm/lists.h>
12 #include <dm/device-internal.h>
13 #include <clk.h>
14
clk_register(struct clk * clk,const char * drv_name,const char * name,const char * parent_name)15 int clk_register(struct clk *clk, const char *drv_name,
16 const char *name, const char *parent_name)
17 {
18 struct udevice *parent;
19 struct driver *drv;
20 int ret;
21
22 ret = uclass_get_device_by_name(UCLASS_CLK, parent_name, &parent);
23 if (ret)
24 printf("%s: UCLASS parent: 0x%p\n", __func__, parent);
25
26 debug("%s: name: %s parent: %s [0x%p]\n", __func__, name, parent->name,
27 parent);
28
29 drv = lists_driver_lookup_name(drv_name);
30 if (!drv) {
31 printf("%s: %s is not a valid driver name\n",
32 __func__, drv_name);
33 return -ENOENT;
34 }
35
36 ret = device_bind(parent, drv, name, NULL, -1, &clk->dev);
37 if (ret) {
38 printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name,
39 ret);
40 return ret;
41 }
42
43 clk->enable_count = 0;
44 /* Store back pointer to clk from udevice */
45 clk->dev->uclass_priv = clk;
46
47 return 0;
48 }
49
clk_generic_get_rate(struct clk * clk)50 ulong clk_generic_get_rate(struct clk *clk)
51 {
52 return clk_get_parent_rate(clk);
53 }
54
clk_hw_get_name(const struct clk * hw)55 const char *clk_hw_get_name(const struct clk *hw)
56 {
57 return hw->dev->name;
58 }
59
clk_dev_binded(struct clk * clk)60 bool clk_dev_binded(struct clk *clk)
61 {
62 if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
63 return true;
64
65 return false;
66 }
67