Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 1 | // 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 | |
| 15 | int 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 Fan | 5dcac2b | 2019-10-22 03:31:08 +0000 | [diff] [blame] | 23 | if (ret) { |
| 24 | printf("%s: name: %s parent: %s [0x%p]\n", |
| 25 | __func__, name, parent->name, parent); |
| 26 | } |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 27 | |
| 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 Fan | e6849e2 | 2019-08-21 13:35:03 +0000 | [diff] [blame] | 45 | clk->enable_count = 0; |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 46 | /* Store back pointer to clk from udevice */ |
| 47 | clk->dev->uclass_priv = clk; |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | ulong clk_generic_get_rate(struct clk *clk) |
| 53 | { |
| 54 | return clk_get_parent_rate(clk); |
| 55 | } |
| 56 | |
| 57 | const char *clk_hw_get_name(const struct clk *hw) |
| 58 | { |
| 59 | return hw->dev->name; |
| 60 | } |
Peng Fan | 2457612 | 2019-07-31 07:01:23 +0000 | [diff] [blame] | 61 | |
| 62 | bool 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 | } |