blob: 1cf9987f6cbb8d87ca69d08ee1c361c62f8ee78f [file] [log] [blame]
Lukasz Majewski1d7993d2019-06-24 15:50:45 +02001// 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
15int 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
Peng Fane6849e22019-08-21 13:35:03 +000043 clk->enable_count = 0;
Lukasz Majewski1d7993d2019-06-24 15:50:45 +020044 /* Store back pointer to clk from udevice */
45 clk->dev->uclass_priv = clk;
46
47 return 0;
48}
49
50ulong clk_generic_get_rate(struct clk *clk)
51{
52 return clk_get_parent_rate(clk);
53}
54
55const char *clk_hw_get_name(const struct clk *hw)
56{
57 return hw->dev->name;
58}
Peng Fan24576122019-07-31 07:01:23 +000059
60bool 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}