Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 3b940fa | 2016-09-13 10:45:59 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 3b940fa | 2016-09-13 10:45:59 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <clk-uclass.h> |
| 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Stephen Warren | 3b940fa | 2016-09-13 10:45:59 -0600 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch-tegra/clk_rst.h> |
| 13 | |
| 14 | static int tegra_car_clk_request(struct clk *clk) |
| 15 | { |
| 16 | debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, |
| 17 | clk->id); |
| 18 | |
| 19 | /* |
| 20 | * Note that the first PERIPH_ID_COUNT clock IDs (where the value |
| 21 | * varies per SoC) are the peripheral clocks, which use a numbering |
| 22 | * scheme that matches HW registers 1:1. There are other clock IDs |
| 23 | * beyond this that are assigned arbitrarily by the Tegra CAR DT |
| 24 | * binding. Due to the implementation of this driver, it currently |
| 25 | * only supports the peripheral IDs. |
| 26 | */ |
| 27 | if (clk->id >= PERIPH_ID_COUNT) |
| 28 | return -EINVAL; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static int tegra_car_clk_free(struct clk *clk) |
| 34 | { |
| 35 | debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, |
| 36 | clk->id); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static ulong tegra_car_clk_get_rate(struct clk *clk) |
| 42 | { |
| 43 | enum clock_id parent; |
| 44 | |
| 45 | debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, |
| 46 | clk->id); |
| 47 | |
| 48 | parent = clock_get_periph_parent(clk->id); |
| 49 | return clock_get_periph_rate(clk->id, parent); |
| 50 | } |
| 51 | |
| 52 | static ulong tegra_car_clk_set_rate(struct clk *clk, ulong rate) |
| 53 | { |
| 54 | enum clock_id parent; |
| 55 | |
| 56 | debug("%s(clk=%p, rate=%lu) (dev=%p, id=%lu)\n", __func__, clk, rate, |
| 57 | clk->dev, clk->id); |
| 58 | |
| 59 | parent = clock_get_periph_parent(clk->id); |
| 60 | return clock_adjust_periph_pll_div(clk->id, parent, rate, NULL); |
| 61 | } |
| 62 | |
| 63 | static int tegra_car_clk_enable(struct clk *clk) |
| 64 | { |
| 65 | debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, |
| 66 | clk->id); |
| 67 | |
| 68 | clock_enable(clk->id); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int tegra_car_clk_disable(struct clk *clk) |
| 74 | { |
| 75 | debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, |
| 76 | clk->id); |
| 77 | |
| 78 | clock_disable(clk->id); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static struct clk_ops tegra_car_clk_ops = { |
| 84 | .request = tegra_car_clk_request, |
Simon Glass | 2cdd3f4 | 2020-02-03 07:35:54 -0700 | [diff] [blame] | 85 | .rfree = tegra_car_clk_free, |
Stephen Warren | 3b940fa | 2016-09-13 10:45:59 -0600 | [diff] [blame] | 86 | .get_rate = tegra_car_clk_get_rate, |
| 87 | .set_rate = tegra_car_clk_set_rate, |
| 88 | .enable = tegra_car_clk_enable, |
| 89 | .disable = tegra_car_clk_disable, |
| 90 | }; |
| 91 | |
| 92 | static int tegra_car_clk_probe(struct udevice *dev) |
| 93 | { |
| 94 | debug("%s(dev=%p)\n", __func__, dev); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | U_BOOT_DRIVER(tegra_car_clk) = { |
| 100 | .name = "tegra_car_clk", |
| 101 | .id = UCLASS_CLK, |
| 102 | .probe = tegra_car_clk_probe, |
| 103 | .ops = &tegra_car_clk_ops, |
| 104 | }; |