Merge branch 'android-tegra-2.6.36' into android-tegra-moto-2.6.36
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-tegra / clock.h
1 /*
2  * arch/arm/mach-tegra/include/mach/clock.h
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
6  * Author:
7  *      Colin Cross <ccross@google.com>
8  *
9  * This software is licensed under the terms of the GNU General Public
10  * License version 2, as published by the Free Software Foundation, and
11  * may be copied, distributed, and modified under those terms.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  */
19
20 #ifndef __MACH_TEGRA_CLOCK_H
21 #define __MACH_TEGRA_CLOCK_H
22
23 #include <linux/list.h>
24 #include <linux/mutex.h>
25 #include <linux/spinlock.h>
26 #include <asm/clkdev.h>
27
28 #define DIV_BUS                 (1 << 0)
29 #define DIV_U71                 (1 << 1)
30 #define DIV_U71_FIXED           (1 << 2)
31 #define DIV_2                   (1 << 3)
32 #define DIV_U16                 (1 << 4)
33 #define PLL_FIXED               (1 << 5)
34 #define PLL_HAS_CPCON           (1 << 6)
35 #define MUX                     (1 << 7)
36 #define PLLD                    (1 << 8)
37 #define PERIPH_NO_RESET         (1 << 9)
38 #define PERIPH_NO_ENB           (1 << 10)
39 #define PERIPH_EMC_ENB          (1 << 11)
40 #define PERIPH_MANUAL_RESET     (1 << 12)
41 #define PLL_ALT_MISC_REG        (1 << 13)
42 #define PLLU                    (1 << 14)
43 #define ENABLE_ON_INIT          (1 << 28)
44
45 struct clk;
46
47 struct clk_mux_sel {
48         struct clk      *input;
49         u32             value;
50 };
51
52 struct clk_pll_freq_table {
53         unsigned long   input_rate;
54         unsigned long   output_rate;
55         u16             n;
56         u16             m;
57         u8              p;
58         u8              cpcon;
59 };
60
61 struct clk_ops {
62         void            (*init)(struct clk *);
63         int             (*enable)(struct clk *);
64         void            (*disable)(struct clk *);
65         int             (*set_parent)(struct clk *, struct clk *);
66         int             (*set_rate)(struct clk *, unsigned long);
67         long            (*round_rate)(struct clk *, unsigned long);
68         void            (*reset)(struct clk *, bool);
69 };
70
71 enum clk_state {
72         UNINITIALIZED = 0,
73         ON,
74         OFF,
75 };
76
77 struct clk {
78         /* node for master clocks list */
79         struct list_head        node;           /* node for list of all clocks */
80         struct dvfs             *dvfs;
81         struct clk_lookup       lookup;
82
83 #ifdef CONFIG_DEBUG_FS
84         struct dentry           *dent;
85         struct dentry           *parent_dent;
86 #endif
87         bool                    set;
88         struct clk_ops          *ops;
89         unsigned long           dvfs_rate;
90         unsigned long           rate;
91         unsigned long           max_rate;
92         unsigned long           min_rate;
93         bool                    auto_dvfs;
94         bool                    cansleep;
95         u32                     flags;
96         const char              *name;
97
98         u32                     refcnt;
99         enum clk_state          state;
100         struct clk              *parent;
101         u32                     div;
102         u32                     mul;
103
104         const struct clk_mux_sel        *inputs;
105         u32                             reg;
106         u32                             reg_shift;
107
108         struct list_head                shared_bus_list;
109
110         union {
111                 struct {
112                         unsigned int                    clk_num;
113                 } periph;
114                 struct {
115                         unsigned long                   input_min;
116                         unsigned long                   input_max;
117                         unsigned long                   cf_min;
118                         unsigned long                   cf_max;
119                         unsigned long                   vco_min;
120                         unsigned long                   vco_max;
121                         const struct clk_pll_freq_table *freq_table;
122                         int                             lock_delay;
123                 } pll;
124                 struct {
125                         u32                             sel;
126                         u32                             reg_mask;
127                 } mux;
128                 struct {
129                         struct clk                      *main;
130                         struct clk                      *backup;
131                 } cpu;
132                 struct {
133                         struct list_head                node;
134                         bool                            enabled;
135                         unsigned long                   rate;
136                 } shared_bus_user;
137         } u;
138
139         struct mutex mutex;
140         spinlock_t spinlock;
141 };
142
143 struct clk_duplicate {
144         const char *name;
145         struct clk_lookup lookup;
146 };
147
148 struct tegra_clk_init_table {
149         const char *name;
150         const char *parent;
151         unsigned long rate;
152         bool enabled;
153 };
154
155 void tegra2_init_clocks(void);
156 void tegra2_periph_reset_deassert(struct clk *c);
157 void tegra2_periph_reset_assert(struct clk *c);
158 void clk_init(struct clk *clk);
159 struct clk *tegra_get_clock_by_name(const char *name);
160 unsigned long clk_measure_input_freq(void);
161 int clk_reparent(struct clk *c, struct clk *parent);
162 void tegra_clk_init_from_table(struct tegra_clk_init_table *table);
163 void clk_set_cansleep(struct clk *c);
164 unsigned long clk_get_rate_locked(struct clk *c);
165
166 #endif