blob: df2aa4ee24d83bea7db93c3f630e5968c063807f [file] [log] [blame]
Brian Swetland600f7cf2008-09-09 11:04:14 -07001/* arch/arm/mach-msm/clock.h
2 *
3 * Copyright (C) 2007 Google, Inc.
Taniya Das7c9f0512011-12-02 14:26:46 +05304 * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved.
Brian Swetland600f7cf2008-09-09 11:04:14 -07005 *
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 Huntsman3f2bc4d2011-08-16 17:27:22 -070020#include <linux/types.h>
Brian Swetland600f7cf2008-09-09 11:04:14 -070021#include <linux/list.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <linux/clkdev.h>
23#include <linux/spinlock.h>
Stephen Boyd3bbf3462012-01-12 00:19:23 -080024#include <linux/mutex.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025
Daniel Walker5e96da52010-05-12 13:43:28 -070026#include <mach/clk.h>
27
Brian Swetland600f7cf2008-09-09 11:04:14 -070028#define CLKFLAG_INVERT 0x00000001
29#define CLKFLAG_NOINVERT 0x00000002
30#define CLKFLAG_NONEST 0x00000004
31#define CLKFLAG_NORESET 0x00000008
Stephen Boyda52d7e32011-11-10 11:59:00 -080032#define CLKFLAG_HWCG 0x00000020
Matt Wagantall7e0b6c92012-01-20 18:48:05 -080033#define CLKFLAG_RETAIN 0x00000040
34#define CLKFLAG_NORETAIN 0x00000080
Matt Wagantall158f73b2012-05-16 11:29:35 -070035#define CLKFLAG_SKIP_HANDOFF 0x00000100
Daniel Walker5e96da52010-05-12 13:43:28 -070036#define CLKFLAG_MIN 0x00000400
37#define CLKFLAG_MAX 0x00000800
38
Vikram Mulukutla681d8682012-03-09 23:56:20 -080039/*
40 * Bit manipulation macros
41 */
42#define BM(msb, lsb) (((((uint32_t)-1) << (31-msb)) >> (31-msb+lsb)) << lsb)
43#define BVAL(msb, lsb, val) (((val) << lsb) & BM(msb, lsb))
44
Vikram Mulukutla8810e342011-10-20 20:26:53 -070045/*
46 * Halt/Status Checking Mode Macros
47 */
48#define HALT 0 /* Bit pol: 1 = halted */
49#define NOCHECK 1 /* No bit to check, do nothing */
50#define HALT_VOTED 2 /* Bit pol: 1 = halted; delay on disable */
51#define ENABLE 3 /* Bit pol: 1 = running */
52#define ENABLE_VOTED 4 /* Bit pol: 1 = running; delay on disable */
53#define DELAY 5 /* No bit to check, just delay */
54
Matt Wagantalle18bbc82011-10-06 10:07:28 -070055#define MAX_VDD_LEVELS 4
56
57/**
58 * struct clk_vdd_class - Voltage scaling class
59 * @class_name: name of the class
60 * @set_vdd: function to call when applying a new voltage setting
61 * @level_votes: array of votes for each level
62 * @cur_level: the currently set voltage level
63 * @lock: lock to protect this struct
64 */
65struct clk_vdd_class {
66 const char *class_name;
67 int (*set_vdd)(struct clk_vdd_class *v_class, int level);
68 int level_votes[MAX_VDD_LEVELS];
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070069 unsigned long cur_level;
Matt Wagantalle18bbc82011-10-06 10:07:28 -070070 spinlock_t lock;
71};
72
73#define DEFINE_VDD_CLASS(_name, _set_vdd) \
74 struct clk_vdd_class _name = { \
75 .class_name = #_name, \
76 .set_vdd = _set_vdd, \
77 .cur_level = ARRAY_SIZE(_name.level_votes), \
78 .lock = __SPIN_LOCK_UNLOCKED(lock) \
79 }
80
Matt Wagantalla15833b2012-04-03 11:00:56 -070081enum handoff {
82 HANDOFF_ENABLED_CLK,
83 HANDOFF_DISABLED_CLK,
84 HANDOFF_UNKNOWN_RATE,
85};
86
Daniel Walker5e96da52010-05-12 13:43:28 -070087struct clk_ops {
Stephen Boyd3bbf3462012-01-12 00:19:23 -080088 int (*prepare)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 int (*enable)(struct clk *clk);
90 void (*disable)(struct clk *clk);
Stephen Boyd3bbf3462012-01-12 00:19:23 -080091 void (*unprepare)(struct clk *clk);
Stephen Boyda52d7e32011-11-10 11:59:00 -080092 void (*enable_hwcg)(struct clk *clk);
93 void (*disable_hwcg)(struct clk *clk);
94 int (*in_hwcg_mode)(struct clk *clk);
Matt Wagantalla15833b2012-04-03 11:00:56 -070095 enum handoff (*handoff)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096 int (*reset)(struct clk *clk, enum clk_reset_action action);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070097 int (*set_rate)(struct clk *clk, unsigned long rate);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070098 int (*set_max_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099 int (*set_flags)(struct clk *clk, unsigned flags);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700100 unsigned long (*get_rate)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101 int (*list_rate)(struct clk *clk, unsigned n);
102 int (*is_enabled)(struct clk *clk);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700103 long (*round_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104 int (*set_parent)(struct clk *clk, struct clk *parent);
105 struct clk *(*get_parent)(struct clk *clk);
106 bool (*is_local)(struct clk *clk);
Daniel Walker5e96da52010-05-12 13:43:28 -0700107};
Brian Swetland600f7cf2008-09-09 11:04:14 -0700108
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109/**
110 * struct clk
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800111 * @prepare_count: prepare refcount
112 * @prepare_lock: protects clk_prepare()/clk_unprepare() path and @prepare_count
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113 * @count: enable refcount
114 * @lock: protects clk_enable()/clk_disable() path and @count
Stephen Boyd7fa26742011-08-11 23:22:29 -0700115 * @depends: non-direct parent of clock to enable when this clock is enabled
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700116 * @vdd_class: voltage scaling requirement class
117 * @fmax: maximum frequency in Hz supported at each voltage level
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800118 * @warned: true if the clock has warned of incorrect usage, false otherwise
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119 */
Brian Swetland600f7cf2008-09-09 11:04:14 -0700120struct clk {
Brian Swetland600f7cf2008-09-09 11:04:14 -0700121 uint32_t flags;
Daniel Walker5e96da52010-05-12 13:43:28 -0700122 struct clk_ops *ops;
123 const char *dbg_name;
Stephen Boyd7fa26742011-08-11 23:22:29 -0700124 struct clk *depends;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700125 struct clk_vdd_class *vdd_class;
126 unsigned long fmax[MAX_VDD_LEVELS];
Matt Wagantall7205eea2011-11-04 17:31:29 -0700127 unsigned long rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128
129 struct list_head children;
130 struct list_head siblings;
131
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800132 bool warned;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 unsigned count;
134 spinlock_t lock;
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800135 unsigned prepare_count;
136 struct mutex prepare_lock;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700137};
138
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139#define CLK_INIT(name) \
140 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800141 .prepare_lock = __MUTEX_INITIALIZER((name).prepare_lock), \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142 .children = LIST_HEAD_INIT((name).children), \
143 .siblings = LIST_HEAD_INIT((name).siblings)
144
Stephen Boydbb600ae2011-08-02 20:11:40 -0700145/**
146 * struct clock_init_data - SoC specific clock initialization data
147 * @table: table of lookups to add
148 * @size: size of @table
Matt Wagantallb64888f2012-04-02 21:35:07 -0700149 * @pre_init: called before initializing the clock driver.
150 * @post_init: called after registering @table. clock APIs can be called inside.
Stephen Boydbb600ae2011-08-02 20:11:40 -0700151 * @late_init: called during late init
152 */
153struct clock_init_data {
154 struct clk_lookup *table;
155 size_t size;
Matt Wagantallb64888f2012-04-02 21:35:07 -0700156 void (*pre_init)(void);
157 void (*post_init)(void);
Stephen Boydbb600ae2011-08-02 20:11:40 -0700158 int (*late_init)(void);
159};
160
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700161extern struct clock_init_data msm9615_clock_init_data;
Tianyi Gou41515e22011-09-01 19:37:43 -0700162extern struct clock_init_data apq8064_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700163extern struct clock_init_data fsm9xxx_clock_init_data;
164extern struct clock_init_data msm7x01a_clock_init_data;
165extern struct clock_init_data msm7x27_clock_init_data;
166extern struct clock_init_data msm7x27a_clock_init_data;
167extern struct clock_init_data msm7x30_clock_init_data;
168extern struct clock_init_data msm8960_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700169extern struct clock_init_data msm8x60_clock_init_data;
170extern struct clock_init_data qds8x50_clock_init_data;
Taniya Das7c9f0512011-12-02 14:26:46 +0530171extern struct clock_init_data msm8625_dummy_clock_init_data;
Tianyi Goue3d4f542012-03-15 17:06:45 -0700172extern struct clock_init_data msm8930_clock_init_data;
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700173extern struct clock_init_data msm8974_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700174
175void msm_clock_init(struct clock_init_data *data);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700176int vote_vdd_level(struct clk_vdd_class *vdd_class, int level);
177int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700178
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800179#ifdef CONFIG_DEBUG_FS
Stephen Boydbb600ae2011-08-02 20:11:40 -0700180int clock_debug_init(struct clock_init_data *data);
181int clock_debug_add(struct clk *clock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700182void clock_debug_print_enabled(void);
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800183#else
Stephen Boyd176d24f2012-07-16 11:22:20 -0700184static inline int clock_debug_init(struct clock_init_data *data) { return 0; }
Stephen Boydbb600ae2011-08-02 20:11:40 -0700185static inline int clock_debug_add(struct clk *clock) { return 0; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186static inline void clock_debug_print_enabled(void) { return; }
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800187#endif
188
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189extern struct clk dummy_clk;
190
191#define CLK_DUMMY(clk_name, clk_id, clk_dev, flags) { \
192 .con_id = clk_name, \
193 .dev_id = clk_dev, \
194 .clk = &dummy_clk, \
195 }
196
197#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
198
Brian Swetland600f7cf2008-09-09 11:04:14 -0700199#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200