blob: 09a7cf470ca2654e237a3e108cddda628446b525 [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 Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Stephen Warren3b940fa2016-09-13 10:45:59 -060011#include <asm/arch/clock.h>
12#include <asm/arch-tegra/clk_rst.h>
13
14static 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
33static 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
41static 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
52static 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
63static 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
73static 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
83static struct clk_ops tegra_car_clk_ops = {
84 .request = tegra_car_clk_request,
Simon Glass2cdd3f42020-02-03 07:35:54 -070085 .rfree = tegra_car_clk_free,
Stephen Warren3b940fa2016-09-13 10:45:59 -060086 .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
92static int tegra_car_clk_probe(struct udevice *dev)
93{
94 debug("%s(dev=%p)\n", __func__, dev);
95
96 return 0;
97}
98
99U_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};