blob: 4c477a488e14fec0d625982ebec96ec84061edc7 [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);
Peng Fan5dcac2b2019-10-22 03:31:08 +000023 if (ret) {
24 printf("%s: name: %s parent: %s [0x%p]\n",
25 __func__, name, parent->name, parent);
26 }
Lukasz Majewski1d7993d2019-06-24 15:50:45 +020027
28 debug("%s: name: %s parent: %s [0x%p]\n", __func__, name, parent->name,
29 parent);
30
31 drv = lists_driver_lookup_name(drv_name);
32 if (!drv) {
33 printf("%s: %s is not a valid driver name\n",
34 __func__, drv_name);
35 return -ENOENT;
36 }
37
38 ret = device_bind(parent, drv, name, NULL, -1, &clk->dev);
39 if (ret) {
40 printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name,
41 ret);
42 return ret;
43 }
44
Peng Fane6849e22019-08-21 13:35:03 +000045 clk->enable_count = 0;
Lukasz Majewski1d7993d2019-06-24 15:50:45 +020046 /* Store back pointer to clk from udevice */
47 clk->dev->uclass_priv = clk;
48
49 return 0;
50}
51
52ulong clk_generic_get_rate(struct clk *clk)
53{
54 return clk_get_parent_rate(clk);
55}
56
57const char *clk_hw_get_name(const struct clk *hw)
58{
59 return hw->dev->name;
60}
Peng Fan24576122019-07-31 07:01:23 +000061
62bool clk_dev_binded(struct clk *clk)
63{
64 if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
65 return true;
66
67 return false;
68}