1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2013 Lucas Stach <l.stach@pengutronix.de>
*
* Based on the Linux Tegra clock code
*/
#include <common.h>
#include <io.h>
#include <malloc.h>
#include <linux/clk.h>
#include <linux/err.h>
#include "clk.h"
#define pll_out_enb(p) (BIT(p->enb_bit_idx))
#define pll_out_rst(p) (BIT(p->rst_bit_idx))
#define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
static int clk_pll_out_is_enabled(struct clk *hw)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
u32 val = readl(pll_out->reg);
int state;
state = (val & pll_out_enb(pll_out)) ? 1 : 0;
if (!(val & (pll_out_rst(pll_out))))
state = 0;
return state;
}
static int clk_pll_out_enable(struct clk *hw)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
u32 val;
val = readl(pll_out->reg);
val |= (pll_out_enb(pll_out) | pll_out_rst(pll_out));
writel(val, pll_out->reg);
udelay(2);
return 0;
}
static void clk_pll_out_disable(struct clk *hw)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
u32 val;
val = readl(pll_out->reg);
val &= ~(pll_out_enb(pll_out) | pll_out_rst(pll_out));
writel(val, pll_out->reg);
udelay(2);
}
static unsigned long clk_pll_out_recalc_rate(struct clk *hw,
unsigned long parent_rate)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
return pll_out->div->ops->recalc_rate(pll_out->div, parent_rate);
}
static long clk_pll_out_round_rate(struct clk *hw, unsigned long rate,
unsigned long *prate)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
return pll_out->div->ops->round_rate(pll_out->div, rate, prate);
}
static int clk_pll_out_set_rate(struct clk *hw, unsigned long rate,
unsigned long parent_rate)
{
struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
return pll_out->div->ops->set_rate(pll_out->div, rate, parent_rate);
}
const struct clk_ops tegra_clk_pll_out_ops = {
.is_enabled = clk_pll_out_is_enabled,
.enable = clk_pll_out_enable,
.disable = clk_pll_out_disable,
.recalc_rate = clk_pll_out_recalc_rate,
.round_rate = clk_pll_out_round_rate,
.set_rate = clk_pll_out_set_rate,
};
struct clk *tegra_clk_register_pll_out(const char *name,
const char *parent_name, void __iomem *reg, u8 shift, u8 divider_flags)
{
struct tegra_clk_pll_out *pll_out;
int ret;
pll_out = kzalloc(sizeof(*pll_out), GFP_KERNEL);
if (!pll_out)
return NULL;
pll_out->div = tegra_clk_divider_alloc(NULL, NULL, reg, 0, divider_flags, shift + 8, 8, 1);
if (!pll_out->div) {
kfree(pll_out);
return NULL;
}
pll_out->parent = parent_name;
pll_out->hw.name = name;
pll_out->hw.ops = &tegra_clk_pll_out_ops;
pll_out->hw.parent_names = (pll_out->parent ? &pll_out->parent : NULL);
pll_out->hw.num_parents = (pll_out->parent ? 1 : 0);
pll_out->reg = reg;
pll_out->enb_bit_idx = shift + 1;
pll_out->rst_bit_idx = shift;
ret = clk_register(&pll_out->hw);
if (ret) {
tegra_clk_divider_free(pll_out->div);
kfree(pll_out);
return ERR_PTR(ret);
}
return &pll_out->hw;
}
|