2019-06-24 13:50:45 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 DENX Software Engineering
|
|
|
|
* Lukasz Majewski, DENX Software Engineering, lukma@denx.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk-uclass.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-06-24 13:50:45 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
#include <dm/lists.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <clk.h>
|
|
|
|
|
|
|
|
int clk_register(struct clk *clk, const char *drv_name,
|
|
|
|
const char *name, const char *parent_name)
|
|
|
|
{
|
|
|
|
struct udevice *parent;
|
|
|
|
struct driver *drv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_name(UCLASS_CLK, parent_name, &parent);
|
2019-10-22 03:31:08 +00:00
|
|
|
if (ret) {
|
2020-05-02 15:38:11 +00:00
|
|
|
printf("%s: failed to get %s device (parent of %s)\n",
|
|
|
|
__func__, parent_name, name);
|
|
|
|
} else {
|
|
|
|
debug("%s: name: %s parent: %s [0x%p]\n", __func__, name,
|
|
|
|
parent->name, parent);
|
2019-10-22 03:31:08 +00:00
|
|
|
}
|
2019-06-24 13:50:45 +00:00
|
|
|
|
|
|
|
drv = lists_driver_lookup_name(drv_name);
|
|
|
|
if (!drv) {
|
|
|
|
printf("%s: %s is not a valid driver name\n",
|
|
|
|
__func__, drv_name);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = device_bind(parent, drv, name, NULL, -1, &clk->dev);
|
|
|
|
if (ret) {
|
|
|
|
printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-21 13:35:03 +00:00
|
|
|
clk->enable_count = 0;
|
2019-06-24 13:50:45 +00:00
|
|
|
/* Store back pointer to clk from udevice */
|
|
|
|
clk->dev->uclass_priv = clk;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong clk_generic_get_rate(struct clk *clk)
|
|
|
|
{
|
|
|
|
return clk_get_parent_rate(clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *clk_hw_get_name(const struct clk *hw)
|
|
|
|
{
|
2020-09-07 14:46:32 +00:00
|
|
|
assert(hw);
|
|
|
|
assert(hw->dev);
|
|
|
|
|
2019-06-24 13:50:45 +00:00
|
|
|
return hw->dev->name;
|
|
|
|
}
|
2019-07-31 07:01:23 +00:00
|
|
|
|
|
|
|
bool clk_dev_binded(struct clk *clk)
|
|
|
|
{
|
|
|
|
if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|