| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 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 |  | 
| Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 23 | #include <linux/clkdev.h> | 
| Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 24 | #include <linux/list.h> | 
 | 25 | #include <linux/spinlock.h> | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 26 |  | 
 | 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 Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 31 | #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 Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 42 | #define ENABLE_ON_INIT		(1 << 28) | 
 | 43 |  | 
 | 44 | struct clk; | 
 | 45 |  | 
 | 46 | struct clk_mux_sel { | 
 | 47 | 	struct clk	*input; | 
 | 48 | 	u32		value; | 
 | 49 | }; | 
 | 50 |  | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 51 | struct clk_pll_freq_table { | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 52 | 	unsigned long	input_rate; | 
 | 53 | 	unsigned long	output_rate; | 
 | 54 | 	u16		n; | 
 | 55 | 	u16		m; | 
 | 56 | 	u8		p; | 
 | 57 | 	u8		cpcon; | 
 | 58 | }; | 
 | 59 |  | 
 | 60 | struct clk_ops { | 
 | 61 | 	void		(*init)(struct clk *); | 
 | 62 | 	int		(*enable)(struct clk *); | 
 | 63 | 	void		(*disable)(struct clk *); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 64 | 	int		(*set_parent)(struct clk *, struct clk *); | 
 | 65 | 	int		(*set_rate)(struct clk *, unsigned long); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 66 | 	long		(*round_rate)(struct clk *, unsigned long); | 
| Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame] | 67 | 	void		(*reset)(struct clk *, bool); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 68 | }; | 
 | 69 |  | 
 | 70 | enum clk_state { | 
 | 71 | 	UNINITIALIZED = 0, | 
 | 72 | 	ON, | 
 | 73 | 	OFF, | 
 | 74 | }; | 
 | 75 |  | 
 | 76 | struct clk { | 
 | 77 | 	/* node for master clocks list */ | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 78 | 	struct list_head	node;		/* node for list of all clocks */ | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 79 | 	struct clk_lookup	lookup; | 
 | 80 |  | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 81 | #ifdef CONFIG_DEBUG_FS | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 82 | 	struct dentry		*dent; | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 83 | #endif | 
| Colin Cross | 4db4afb | 2011-02-20 23:35:07 -0800 | [diff] [blame] | 84 | 	bool			set; | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 85 | 	struct clk_ops		*ops; | 
 | 86 | 	unsigned long		rate; | 
 | 87 | 	unsigned long		max_rate; | 
| Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 88 | 	unsigned long		min_rate; | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 89 | 	u32			flags; | 
 | 90 | 	const char		*name; | 
 | 91 |  | 
 | 92 | 	u32			refcnt; | 
 | 93 | 	enum clk_state		state; | 
 | 94 | 	struct clk		*parent; | 
 | 95 | 	u32			div; | 
 | 96 | 	u32			mul; | 
 | 97 |  | 
 | 98 | 	const struct clk_mux_sel	*inputs; | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 99 | 	u32				reg; | 
 | 100 | 	u32				reg_shift; | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 101 |  | 
| Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 102 | 	struct list_head		shared_bus_list; | 
 | 103 |  | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 104 | 	union { | 
 | 105 | 		struct { | 
 | 106 | 			unsigned int			clk_num; | 
 | 107 | 		} periph; | 
 | 108 | 		struct { | 
 | 109 | 			unsigned long			input_min; | 
 | 110 | 			unsigned long			input_max; | 
 | 111 | 			unsigned long			cf_min; | 
 | 112 | 			unsigned long			cf_max; | 
 | 113 | 			unsigned long			vco_min; | 
 | 114 | 			unsigned long			vco_max; | 
 | 115 | 			const struct clk_pll_freq_table	*freq_table; | 
 | 116 | 			int				lock_delay; | 
 | 117 | 		} pll; | 
 | 118 | 		struct { | 
 | 119 | 			u32				sel; | 
 | 120 | 			u32				reg_mask; | 
 | 121 | 		} mux; | 
 | 122 | 		struct { | 
 | 123 | 			struct clk			*main; | 
 | 124 | 			struct clk			*backup; | 
 | 125 | 		} cpu; | 
| Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 126 | 		struct { | 
 | 127 | 			struct list_head		node; | 
 | 128 | 			bool				enabled; | 
 | 129 | 			unsigned long			rate; | 
 | 130 | 		} shared_bus_user; | 
| Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 131 | 	} u; | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 132 |  | 
| Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 133 | 	spinlock_t spinlock; | 
 | 134 | }; | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 135 |  | 
 | 136 | struct clk_duplicate { | 
 | 137 | 	const char *name; | 
 | 138 | 	struct clk_lookup lookup; | 
 | 139 | }; | 
 | 140 |  | 
 | 141 | struct tegra_clk_init_table { | 
 | 142 | 	const char *name; | 
 | 143 | 	const char *parent; | 
 | 144 | 	unsigned long rate; | 
 | 145 | 	bool enabled; | 
 | 146 | }; | 
 | 147 |  | 
 | 148 | void tegra2_init_clocks(void); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 149 | void clk_init(struct clk *clk); | 
 | 150 | struct clk *tegra_get_clock_by_name(const char *name); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 151 | int clk_reparent(struct clk *c, struct clk *parent); | 
 | 152 | void tegra_clk_init_from_table(struct tegra_clk_init_table *table); | 
| Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 153 | unsigned long clk_get_rate_locked(struct clk *c); | 
 | 154 | int clk_set_rate_locked(struct clk *c, unsigned long rate); | 
| Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 155 |  | 
 | 156 | #endif |