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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 10 | #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 | |
| 16 | int 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 Fan | 5dcac2b | 2019-10-22 03:31:08 +0000 | [diff] [blame] | 24 | if (ret) { |
Dario Binacchi | 7b0830d | 2020-05-02 17:38:11 +0200 | [diff] [blame] | 25 | 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 Fan | 5dcac2b | 2019-10-22 03:31:08 +0000 | [diff] [blame] | 30 | } |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 31 | |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 32 | 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 Glass | a2703ce | 2020-11-28 17:50:03 -0700 | [diff] [blame] | 39 | ret = device_bind(parent, drv, name, NULL, ofnode_null(), &clk->dev); |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 40 | if (ret) { |
| 41 | printf("%s: CLK: %s driver bind error [%d]!\n", __func__, name, |
| 42 | ret); |
| 43 | return ret; |
| 44 | } |
| 45 | |
Peng Fan | e6849e2 | 2019-08-21 13:35:03 +0000 | [diff] [blame] | 46 | clk->enable_count = 0; |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame^] | 47 | |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 48 | /* Store back pointer to clk from udevice */ |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame^] | 49 | /* FIXME: This is not allowed...should be allocated by driver model */ |
| 50 | dev_set_uclass_priv(clk->dev, clk); |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | ulong clk_generic_get_rate(struct clk *clk) |
| 56 | { |
| 57 | return clk_get_parent_rate(clk); |
| 58 | } |
| 59 | |
| 60 | const char *clk_hw_get_name(const struct clk *hw) |
| 61 | { |
Claudiu Beznea | b04da9f | 2020-09-07 17:46:32 +0300 | [diff] [blame] | 62 | assert(hw); |
| 63 | assert(hw->dev); |
| 64 | |
Lukasz Majewski | 1d7993d | 2019-06-24 15:50:45 +0200 | [diff] [blame] | 65 | return hw->dev->name; |
| 66 | } |
Peng Fan | 2457612 | 2019-07-31 07:01:23 +0000 | [diff] [blame] | 67 | |
| 68 | bool clk_dev_binded(struct clk *clk) |
| 69 | { |
| 70 | if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND)) |
| 71 | return true; |
| 72 | |
| 73 | return false; |
| 74 | } |