Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/clock.h |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Taniya Das | 7c9f051 | 2011-12-02 14:26:46 +0530 | [diff] [blame] | 4 | * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved. |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #ifndef __ARCH_ARM_MACH_MSM_CLOCK_H |
| 18 | #define __ARCH_ARM_MACH_MSM_CLOCK_H |
| 19 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/types.h> |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 21 | #include <linux/list.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <linux/clkdev.h> |
| 23 | #include <linux/spinlock.h> |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 26 | #include <mach/clk.h> |
| 27 | |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 28 | #define CLKFLAG_INVERT 0x00000001 |
| 29 | #define CLKFLAG_NOINVERT 0x00000002 |
| 30 | #define CLKFLAG_NONEST 0x00000004 |
| 31 | #define CLKFLAG_NORESET 0x00000008 |
Matt Wagantall | 14dc2af | 2011-08-12 13:16:06 -0700 | [diff] [blame] | 32 | #define CLKFLAG_HANDOFF_RATE 0x00000010 |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 33 | #define CLKFLAG_HWCG 0x00000020 |
Matt Wagantall | 7e0b6c9 | 2012-01-20 18:48:05 -0800 | [diff] [blame] | 34 | #define CLKFLAG_RETAIN 0x00000040 |
| 35 | #define CLKFLAG_NORETAIN 0x00000080 |
Matt Wagantall | 22b0a79 | 2011-08-01 16:39:48 -0700 | [diff] [blame] | 36 | #define CLKFLAG_SKIP_AUTO_OFF 0x00000200 |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 37 | #define CLKFLAG_MIN 0x00000400 |
| 38 | #define CLKFLAG_MAX 0x00000800 |
| 39 | |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 40 | /* |
| 41 | * Bit manipulation macros |
| 42 | */ |
| 43 | #define BM(msb, lsb) (((((uint32_t)-1) << (31-msb)) >> (31-msb+lsb)) << lsb) |
| 44 | #define BVAL(msb, lsb, val) (((val) << lsb) & BM(msb, lsb)) |
| 45 | |
Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 46 | /* |
| 47 | * Halt/Status Checking Mode Macros |
| 48 | */ |
| 49 | #define HALT 0 /* Bit pol: 1 = halted */ |
| 50 | #define NOCHECK 1 /* No bit to check, do nothing */ |
| 51 | #define HALT_VOTED 2 /* Bit pol: 1 = halted; delay on disable */ |
| 52 | #define ENABLE 3 /* Bit pol: 1 = running */ |
| 53 | #define ENABLE_VOTED 4 /* Bit pol: 1 = running; delay on disable */ |
| 54 | #define DELAY 5 /* No bit to check, just delay */ |
| 55 | |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 56 | #define MAX_VDD_LEVELS 4 |
| 57 | |
| 58 | /** |
| 59 | * struct clk_vdd_class - Voltage scaling class |
| 60 | * @class_name: name of the class |
| 61 | * @set_vdd: function to call when applying a new voltage setting |
| 62 | * @level_votes: array of votes for each level |
| 63 | * @cur_level: the currently set voltage level |
| 64 | * @lock: lock to protect this struct |
| 65 | */ |
| 66 | struct clk_vdd_class { |
| 67 | const char *class_name; |
| 68 | int (*set_vdd)(struct clk_vdd_class *v_class, int level); |
| 69 | int level_votes[MAX_VDD_LEVELS]; |
Matt Wagantall | 9de3bfb | 2011-11-03 20:13:12 -0700 | [diff] [blame] | 70 | unsigned long cur_level; |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 71 | spinlock_t lock; |
| 72 | }; |
| 73 | |
| 74 | #define DEFINE_VDD_CLASS(_name, _set_vdd) \ |
| 75 | struct clk_vdd_class _name = { \ |
| 76 | .class_name = #_name, \ |
| 77 | .set_vdd = _set_vdd, \ |
| 78 | .cur_level = ARRAY_SIZE(_name.level_votes), \ |
| 79 | .lock = __SPIN_LOCK_UNLOCKED(lock) \ |
| 80 | } |
| 81 | |
Matt Wagantall | a15833b | 2012-04-03 11:00:56 -0700 | [diff] [blame] | 82 | enum handoff { |
| 83 | HANDOFF_ENABLED_CLK, |
| 84 | HANDOFF_DISABLED_CLK, |
| 85 | HANDOFF_UNKNOWN_RATE, |
| 86 | }; |
| 87 | |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 88 | struct clk_ops { |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 89 | int (*prepare)(struct clk *clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | int (*enable)(struct clk *clk); |
| 91 | void (*disable)(struct clk *clk); |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 92 | void (*unprepare)(struct clk *clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | void (*auto_off)(struct clk *clk); |
Stephen Boyd | a52d7e3 | 2011-11-10 11:59:00 -0800 | [diff] [blame] | 94 | void (*enable_hwcg)(struct clk *clk); |
| 95 | void (*disable_hwcg)(struct clk *clk); |
| 96 | int (*in_hwcg_mode)(struct clk *clk); |
Matt Wagantall | a15833b | 2012-04-03 11:00:56 -0700 | [diff] [blame] | 97 | enum handoff (*handoff)(struct clk *clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | int (*reset)(struct clk *clk, enum clk_reset_action action); |
Matt Wagantall | 9de3bfb | 2011-11-03 20:13:12 -0700 | [diff] [blame] | 99 | int (*set_rate)(struct clk *clk, unsigned long rate); |
Matt Wagantall | 9de3bfb | 2011-11-03 20:13:12 -0700 | [diff] [blame] | 100 | int (*set_max_rate)(struct clk *clk, unsigned long rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | int (*set_flags)(struct clk *clk, unsigned flags); |
Matt Wagantall | 9de3bfb | 2011-11-03 20:13:12 -0700 | [diff] [blame] | 102 | unsigned long (*get_rate)(struct clk *clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | int (*list_rate)(struct clk *clk, unsigned n); |
| 104 | int (*is_enabled)(struct clk *clk); |
Matt Wagantall | 9de3bfb | 2011-11-03 20:13:12 -0700 | [diff] [blame] | 105 | long (*round_rate)(struct clk *clk, unsigned long rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 106 | int (*set_parent)(struct clk *clk, struct clk *parent); |
| 107 | struct clk *(*get_parent)(struct clk *clk); |
| 108 | bool (*is_local)(struct clk *clk); |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 109 | }; |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 110 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | /** |
| 112 | * struct clk |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 113 | * @prepare_count: prepare refcount |
| 114 | * @prepare_lock: protects clk_prepare()/clk_unprepare() path and @prepare_count |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 115 | * @count: enable refcount |
| 116 | * @lock: protects clk_enable()/clk_disable() path and @count |
Stephen Boyd | 7fa2674 | 2011-08-11 23:22:29 -0700 | [diff] [blame] | 117 | * @depends: non-direct parent of clock to enable when this clock is enabled |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 118 | * @vdd_class: voltage scaling requirement class |
| 119 | * @fmax: maximum frequency in Hz supported at each voltage level |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 120 | * @warned: true if the clock has warned of incorrect usage, false otherwise |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | */ |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 122 | struct clk { |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 123 | uint32_t flags; |
Daniel Walker | 5e96da5 | 2010-05-12 13:43:28 -0700 | [diff] [blame] | 124 | struct clk_ops *ops; |
| 125 | const char *dbg_name; |
Stephen Boyd | 7fa2674 | 2011-08-11 23:22:29 -0700 | [diff] [blame] | 126 | struct clk *depends; |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 127 | struct clk_vdd_class *vdd_class; |
| 128 | unsigned long fmax[MAX_VDD_LEVELS]; |
Matt Wagantall | 7205eea | 2011-11-04 17:31:29 -0700 | [diff] [blame] | 129 | unsigned long rate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 130 | |
| 131 | struct list_head children; |
| 132 | struct list_head siblings; |
| 133 | |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 134 | bool warned; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 135 | unsigned count; |
| 136 | spinlock_t lock; |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 137 | unsigned prepare_count; |
| 138 | struct mutex prepare_lock; |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | #define CLK_INIT(name) \ |
| 142 | .lock = __SPIN_LOCK_UNLOCKED((name).lock), \ |
Stephen Boyd | 3bbf346 | 2012-01-12 00:19:23 -0800 | [diff] [blame] | 143 | .prepare_lock = __MUTEX_INITIALIZER((name).prepare_lock), \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 144 | .children = LIST_HEAD_INIT((name).children), \ |
| 145 | .siblings = LIST_HEAD_INIT((name).siblings) |
| 146 | |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 147 | /** |
| 148 | * struct clock_init_data - SoC specific clock initialization data |
| 149 | * @table: table of lookups to add |
| 150 | * @size: size of @table |
Matt Wagantall | b64888f | 2012-04-02 21:35:07 -0700 | [diff] [blame] | 151 | * @pre_init: called before initializing the clock driver. |
| 152 | * @post_init: called after registering @table. clock APIs can be called inside. |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 153 | * @late_init: called during late init |
| 154 | */ |
| 155 | struct clock_init_data { |
| 156 | struct clk_lookup *table; |
| 157 | size_t size; |
Matt Wagantall | b64888f | 2012-04-02 21:35:07 -0700 | [diff] [blame] | 158 | void (*pre_init)(void); |
| 159 | void (*post_init)(void); |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 160 | int (*late_init)(void); |
| 161 | }; |
| 162 | |
Vikram Mulukutla | 489e39e | 2011-08-31 18:04:05 -0700 | [diff] [blame] | 163 | extern struct clock_init_data msm9615_clock_init_data; |
Tianyi Gou | 41515e2 | 2011-09-01 19:37:43 -0700 | [diff] [blame] | 164 | extern struct clock_init_data apq8064_clock_init_data; |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 165 | extern struct clock_init_data fsm9xxx_clock_init_data; |
| 166 | extern struct clock_init_data msm7x01a_clock_init_data; |
| 167 | extern struct clock_init_data msm7x27_clock_init_data; |
| 168 | extern struct clock_init_data msm7x27a_clock_init_data; |
| 169 | extern struct clock_init_data msm7x30_clock_init_data; |
| 170 | extern struct clock_init_data msm8960_clock_init_data; |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 171 | extern struct clock_init_data msm8x60_clock_init_data; |
| 172 | extern struct clock_init_data qds8x50_clock_init_data; |
Taniya Das | 7c9f051 | 2011-12-02 14:26:46 +0530 | [diff] [blame] | 173 | extern struct clock_init_data msm8625_dummy_clock_init_data; |
Tianyi Gou | e3d4f54 | 2012-03-15 17:06:45 -0700 | [diff] [blame] | 174 | extern struct clock_init_data msm8930_clock_init_data; |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 175 | extern struct clock_init_data msmcopper_clock_init_data; |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 176 | |
| 177 | void msm_clock_init(struct clock_init_data *data); |
Matt Wagantall | e18bbc8 | 2011-10-06 10:07:28 -0700 | [diff] [blame] | 178 | int vote_vdd_level(struct clk_vdd_class *vdd_class, int level); |
| 179 | int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level); |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 180 | |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 181 | #ifdef CONFIG_DEBUG_FS |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 182 | int clock_debug_init(struct clock_init_data *data); |
| 183 | int clock_debug_add(struct clk *clock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 184 | void clock_debug_print_enabled(void); |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 185 | #else |
Stephen Boyd | bb600ae | 2011-08-02 20:11:40 -0700 | [diff] [blame] | 186 | static inline int clock_debug_init(struct clk_init_data *data) { return 0; } |
| 187 | static inline int clock_debug_add(struct clk *clock) { return 0; } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 188 | static inline void clock_debug_print_enabled(void) { return; } |
Matt Wagantall | d64560fe | 2011-01-26 16:20:54 -0800 | [diff] [blame] | 189 | #endif |
| 190 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | extern struct clk dummy_clk; |
| 192 | |
| 193 | #define CLK_DUMMY(clk_name, clk_id, clk_dev, flags) { \ |
| 194 | .con_id = clk_name, \ |
| 195 | .dev_id = clk_dev, \ |
| 196 | .clk = &dummy_clk, \ |
| 197 | } |
| 198 | |
| 199 | #define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev } |
| 200 | |
Brian Swetland | 600f7cf | 2008-09-09 11:04:14 -0700 | [diff] [blame] | 201 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 202 | |