blob: a63dbf93d9b01cc03b18eda111fa0d2673377761 [file] [log] [blame]
Colin Crossd8611962010-01-28 16:40:29 -08001/*
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
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010023#include <linux/clkdev.h>
Colin Cross4729fd72011-02-12 16:43:05 -080024#include <linux/list.h>
25#include <linux/spinlock.h>
Colin Crossd8611962010-01-28 16:40:29 -080026
27#define DIV_BUS (1 << 0)
28#define DIV_U71 (1 << 1)
29#define DIV_U71_FIXED (1 << 2)
30#define DIV_2 (1 << 3)
Colin Cross71fc84c2010-06-07 20:49:46 -070031#define DIV_U16 (1 << 4)
32#define PLL_FIXED (1 << 5)
33#define PLL_HAS_CPCON (1 << 6)
34#define MUX (1 << 7)
35#define PLLD (1 << 8)
36#define PERIPH_NO_RESET (1 << 9)
37#define PERIPH_NO_ENB (1 << 10)
38#define PERIPH_EMC_ENB (1 << 11)
39#define PERIPH_MANUAL_RESET (1 << 12)
40#define PLL_ALT_MISC_REG (1 << 13)
41#define PLLU (1 << 14)
Colin Crossd8611962010-01-28 16:40:29 -080042#define ENABLE_ON_INIT (1 << 28)
43
44struct clk;
45
46struct clk_mux_sel {
47 struct clk *input;
48 u32 value;
49};
50
Colin Crossf1519612011-02-12 16:05:31 -080051struct clk_pll_freq_table {
Colin Crossd8611962010-01-28 16:40:29 -080052 unsigned long input_rate;
53 unsigned long output_rate;
54 u16 n;
55 u16 m;
56 u8 p;
57 u8 cpcon;
58};
59
60struct clk_ops {
61 void (*init)(struct clk *);
62 int (*enable)(struct clk *);
63 void (*disable)(struct clk *);
Colin Crossd8611962010-01-28 16:40:29 -080064 int (*set_parent)(struct clk *, struct clk *);
65 int (*set_rate)(struct clk *, unsigned long);
Colin Crossd8611962010-01-28 16:40:29 -080066 long (*round_rate)(struct clk *, unsigned long);
Dima Zavin2b84cb4f2010-09-02 19:11:11 -070067 void (*reset)(struct clk *, bool);
Colin Crossd8611962010-01-28 16:40:29 -080068};
69
70enum clk_state {
71 UNINITIALIZED = 0,
72 ON,
73 OFF,
74};
75
76struct clk {
77 /* node for master clocks list */
Colin Crossf1519612011-02-12 16:05:31 -080078 struct list_head node; /* node for list of all clocks */
Colin Crossf1519612011-02-12 16:05:31 -080079 struct clk_lookup lookup;
80
Colin Crossd8611962010-01-28 16:40:29 -080081#ifdef CONFIG_DEBUG_FS
Colin Crossf1519612011-02-12 16:05:31 -080082 struct dentry *dent;
83 bool set;
Colin Crossd8611962010-01-28 16:40:29 -080084#endif
Colin Crossf1519612011-02-12 16:05:31 -080085 struct clk_ops *ops;
86 unsigned long rate;
87 unsigned long max_rate;
88 u32 flags;
89 const char *name;
90
91 u32 refcnt;
92 enum clk_state state;
93 struct clk *parent;
94 u32 div;
95 u32 mul;
96
97 const struct clk_mux_sel *inputs;
Colin Crossd8611962010-01-28 16:40:29 -080098 u32 reg;
99 u32 reg_shift;
Colin Crossd8611962010-01-28 16:40:29 -0800100
Colin Crossf1519612011-02-12 16:05:31 -0800101 union {
102 struct {
103 unsigned int clk_num;
104 } periph;
105 struct {
106 unsigned long input_min;
107 unsigned long input_max;
108 unsigned long cf_min;
109 unsigned long cf_max;
110 unsigned long vco_min;
111 unsigned long vco_max;
112 const struct clk_pll_freq_table *freq_table;
113 int lock_delay;
114 } pll;
115 struct {
116 u32 sel;
117 u32 reg_mask;
118 } mux;
119 struct {
120 struct clk *main;
121 struct clk *backup;
122 } cpu;
123 } u;
Colin Crossd8611962010-01-28 16:40:29 -0800124
Colin Cross4729fd72011-02-12 16:43:05 -0800125 spinlock_t spinlock;
126};
Colin Crossd8611962010-01-28 16:40:29 -0800127
128struct clk_duplicate {
129 const char *name;
130 struct clk_lookup lookup;
131};
132
133struct tegra_clk_init_table {
134 const char *name;
135 const char *parent;
136 unsigned long rate;
137 bool enabled;
138};
139
140void tegra2_init_clocks(void);
141void tegra2_periph_reset_deassert(struct clk *c);
142void tegra2_periph_reset_assert(struct clk *c);
143void clk_init(struct clk *clk);
144struct clk *tegra_get_clock_by_name(const char *name);
145unsigned long clk_measure_input_freq(void);
Colin Crossd8611962010-01-28 16:40:29 -0800146int clk_reparent(struct clk *c, struct clk *parent);
147void tegra_clk_init_from_table(struct tegra_clk_init_table *table);
Colin Cross4729fd72011-02-12 16:43:05 -0800148unsigned long clk_get_rate_locked(struct clk *c);
149int clk_set_rate_locked(struct clk *c, unsigned long rate);
Colin Crossd8611962010-01-28 16:40:29 -0800150
151#endif