blob: 1fa9bec6fea3ce9495bb3defa0bc52c02cabafa6 [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>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020010#include <dm/device.h>
11#include <dm/uclass.h>
12#include <dm/lists.h>
13#include <dm/device-internal.h>
14#include <clk.h>
15
16int clk_register(struct clk *clk, const char *drv_name,
17 const char *name, const char *parent_name)
18{
19 struct udevice *parent;
20 struct driver *drv;
21 int ret;
22
23 ret = uclass_get_device_by_name(UCLASS_CLK, parent_name, &parent);
Peng Fanc179a172019-10-22 03:31:08 +000024 if (ret) {
Dario Binacchi8e312c52020-05-02 17:38:11 +020025 printf("%s: failed to get %s device (parent of %s)\n",
26 __func__, parent_name, name);
27 } else {
28 debug("%s: name: %s parent: %s [0x%p]\n", __func__, name,
29 parent->name, parent);
Peng Fanc179a172019-10-22 03:31:08 +000030 }
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020031
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020032 drv = lists_driver_lookup_name(drv_name);
33 if (!drv) {
34 printf("%s: %s is not a valid driver name\n",
35 __func__, drv_name);
36 return -ENOENT;
37 }
38
Simon Glassf8465372020-11-28 17:50:00 -070039 ret = device_bind_offset(parent, drv, name, NULL, -1, &clk->dev);
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020040 if (ret) {
41 printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name,
42 ret);
43 return ret;
44 }
45
Peng Fan30a6ebc2019-08-21 13:35:03 +000046 clk->enable_count = 0;
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020047 /* Store back pointer to clk from udevice */
48 clk->dev->uclass_priv = clk;
49
50 return 0;
51}
52
53ulong clk_generic_get_rate(struct clk *clk)
54{
55 return clk_get_parent_rate(clk);
56}
57
58const char *clk_hw_get_name(const struct clk *hw)
59{
Claudiu Beznead3e49d02020-09-07 17:46:32 +030060 assert(hw);
61 assert(hw->dev);
62
Lukasz Majewski4de44bb2019-06-24 15:50:45 +020063 return hw->dev->name;
64}
Peng Fan1d0a50a2019-07-31 07:01:23 +000065
66bool clk_dev_binded(struct clk *clk)
67{
68 if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
69 return true;
70
71 return false;
72}