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