blob: 91121e67f5a9caac0fa5152039b6028ee685a16a [file] [log] [blame]
Brian Swetland600f7cf2008-09-09 11:04:14 -07001/* arch/arm/mach-msm/clock.h
2 *
3 * Copyright (C) 2007 Google, Inc.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * Copyright (c) 2007-2011, 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>
24
Daniel Walker5e96da52010-05-12 13:43:28 -070025#include <mach/clk.h>
26
Brian Swetland600f7cf2008-09-09 11:04:14 -070027#define CLKFLAG_INVERT 0x00000001
28#define CLKFLAG_NOINVERT 0x00000002
29#define CLKFLAG_NONEST 0x00000004
30#define CLKFLAG_NORESET 0x00000008
Matt Wagantall14dc2af2011-08-12 13:16:06 -070031#define CLKFLAG_HANDOFF_RATE 0x00000010
Stephen Boyda52d7e32011-11-10 11:59:00 -080032#define CLKFLAG_HWCG 0x00000020
Matt Wagantall22b0a792011-08-01 16:39:48 -070033#define CLKFLAG_SKIP_AUTO_OFF 0x00000200
Daniel Walker5e96da52010-05-12 13:43:28 -070034#define CLKFLAG_MIN 0x00000400
35#define CLKFLAG_MAX 0x00000800
36
Matt Wagantalle18bbc82011-10-06 10:07:28 -070037#define MAX_VDD_LEVELS 4
38
39/**
40 * struct clk_vdd_class - Voltage scaling class
41 * @class_name: name of the class
42 * @set_vdd: function to call when applying a new voltage setting
43 * @level_votes: array of votes for each level
44 * @cur_level: the currently set voltage level
45 * @lock: lock to protect this struct
46 */
47struct clk_vdd_class {
48 const char *class_name;
49 int (*set_vdd)(struct clk_vdd_class *v_class, int level);
50 int level_votes[MAX_VDD_LEVELS];
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070051 unsigned long cur_level;
Matt Wagantalle18bbc82011-10-06 10:07:28 -070052 spinlock_t lock;
53};
54
55#define DEFINE_VDD_CLASS(_name, _set_vdd) \
56 struct clk_vdd_class _name = { \
57 .class_name = #_name, \
58 .set_vdd = _set_vdd, \
59 .cur_level = ARRAY_SIZE(_name.level_votes), \
60 .lock = __SPIN_LOCK_UNLOCKED(lock) \
61 }
62
Daniel Walker5e96da52010-05-12 13:43:28 -070063struct clk_ops {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064 int (*enable)(struct clk *clk);
65 void (*disable)(struct clk *clk);
66 void (*auto_off)(struct clk *clk);
Stephen Boyda52d7e32011-11-10 11:59:00 -080067 void (*enable_hwcg)(struct clk *clk);
68 void (*disable_hwcg)(struct clk *clk);
69 int (*in_hwcg_mode)(struct clk *clk);
Matt Wagantall271a6cd2011-09-20 16:06:31 -070070 int (*handoff)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071 int (*reset)(struct clk *clk, enum clk_reset_action action);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070072 int (*set_rate)(struct clk *clk, unsigned long rate);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070073 int (*set_max_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074 int (*set_flags)(struct clk *clk, unsigned flags);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070075 unsigned long (*get_rate)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076 int (*list_rate)(struct clk *clk, unsigned n);
77 int (*is_enabled)(struct clk *clk);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070078 long (*round_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070079 int (*set_parent)(struct clk *clk, struct clk *parent);
80 struct clk *(*get_parent)(struct clk *clk);
81 bool (*is_local)(struct clk *clk);
Daniel Walker5e96da52010-05-12 13:43:28 -070082};
Brian Swetland600f7cf2008-09-09 11:04:14 -070083
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084/**
85 * struct clk
86 * @count: enable refcount
87 * @lock: protects clk_enable()/clk_disable() path and @count
Stephen Boyd7fa26742011-08-11 23:22:29 -070088 * @depends: non-direct parent of clock to enable when this clock is enabled
Matt Wagantalle18bbc82011-10-06 10:07:28 -070089 * @vdd_class: voltage scaling requirement class
90 * @fmax: maximum frequency in Hz supported at each voltage level
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091 */
Brian Swetland600f7cf2008-09-09 11:04:14 -070092struct clk {
Brian Swetland600f7cf2008-09-09 11:04:14 -070093 uint32_t flags;
Daniel Walker5e96da52010-05-12 13:43:28 -070094 struct clk_ops *ops;
95 const char *dbg_name;
Stephen Boyd7fa26742011-08-11 23:22:29 -070096 struct clk *depends;
Matt Wagantalle18bbc82011-10-06 10:07:28 -070097 struct clk_vdd_class *vdd_class;
98 unsigned long fmax[MAX_VDD_LEVELS];
Matt Wagantall7205eea2011-11-04 17:31:29 -070099 unsigned long rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100
101 struct list_head children;
102 struct list_head siblings;
103
104 unsigned count;
105 spinlock_t lock;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700106};
107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108#define CLK_INIT(name) \
109 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
110 .children = LIST_HEAD_INIT((name).children), \
111 .siblings = LIST_HEAD_INIT((name).siblings)
112
Stephen Boydbb600ae2011-08-02 20:11:40 -0700113/**
114 * struct clock_init_data - SoC specific clock initialization data
115 * @table: table of lookups to add
116 * @size: size of @table
117 * @init: called before registering @table
118 * @late_init: called during late init
119 */
120struct clock_init_data {
121 struct clk_lookup *table;
122 size_t size;
123 void (*init)(void);
124 int (*late_init)(void);
125};
126
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700127extern struct clock_init_data msm9615_clock_init_data;
Tianyi Gou41515e22011-09-01 19:37:43 -0700128extern struct clock_init_data apq8064_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700129extern struct clock_init_data apq8064_dummy_clock_init_data;
130extern struct clock_init_data fsm9xxx_clock_init_data;
131extern struct clock_init_data msm7x01a_clock_init_data;
132extern struct clock_init_data msm7x27_clock_init_data;
133extern struct clock_init_data msm7x27a_clock_init_data;
134extern struct clock_init_data msm7x30_clock_init_data;
135extern struct clock_init_data msm8960_clock_init_data;
136extern struct clock_init_data msm8960_dummy_clock_init_data;
137extern struct clock_init_data msm8x60_clock_init_data;
138extern struct clock_init_data qds8x50_clock_init_data;
139
140void msm_clock_init(struct clock_init_data *data);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700141int vote_vdd_level(struct clk_vdd_class *vdd_class, int level);
142int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700143
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800144#ifdef CONFIG_DEBUG_FS
Stephen Boydbb600ae2011-08-02 20:11:40 -0700145int clock_debug_init(struct clock_init_data *data);
146int clock_debug_add(struct clk *clock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147void clock_debug_print_enabled(void);
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800148#else
Stephen Boydbb600ae2011-08-02 20:11:40 -0700149static inline int clock_debug_init(struct clk_init_data *data) { return 0; }
150static inline int clock_debug_add(struct clk *clock) { return 0; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151static inline void clock_debug_print_enabled(void) { return; }
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800152#endif
153
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154extern struct clk dummy_clk;
155
156#define CLK_DUMMY(clk_name, clk_id, clk_dev, flags) { \
157 .con_id = clk_name, \
158 .dev_id = clk_dev, \
159 .clk = &dummy_clk, \
160 }
161
162#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
163
Brian Swetland600f7cf2008-09-09 11:04:14 -0700164#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165