blob: 39b3087067a63b097b4c6b5d03e378c66f7b1fb6 [file] [log] [blame]
Lukasz Majewski4de44bb2019-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
43 /* Store back pointer to clk from udevice */
44 clk->dev->uclass_priv = clk;
45
46 return 0;
47}
48
49ulong clk_generic_get_rate(struct clk *clk)
50{
51 return clk_get_parent_rate(clk);
52}
53
54const char *clk_hw_get_name(const struct clk *hw)
55{
56 return hw->dev->name;
57}
Peng Fan1d0a50a2019-07-31 07:01:23 +000058
59bool clk_dev_binded(struct clk *clk)
60{
61 if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
62 return true;
63
64 return false;
65}