blob: 785e83848d6396f92ee17be51a2986a2a5cb25bf [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
Matt Wagantall14dc2af2011-08-12 13:16:06 -070032#define CLKFLAG_HANDOFF_RATE 0x00000010
Stephen Boyda52d7e32011-11-10 11:59:00 -080033#define CLKFLAG_HWCG 0x00000020
Matt Wagantall7e0b6c92012-01-20 18:48:05 -080034#define CLKFLAG_RETAIN 0x00000040
35#define CLKFLAG_NORETAIN 0x00000080
Matt Wagantall22b0a792011-08-01 16:39:48 -070036#define CLKFLAG_SKIP_AUTO_OFF 0x00000200
Daniel Walker5e96da52010-05-12 13:43:28 -070037#define CLKFLAG_MIN 0x00000400
38#define CLKFLAG_MAX 0x00000800
39
Matt Wagantalle18bbc82011-10-06 10:07:28 -070040#define MAX_VDD_LEVELS 4
41
42/**
43 * struct clk_vdd_class - Voltage scaling class
44 * @class_name: name of the class
45 * @set_vdd: function to call when applying a new voltage setting
46 * @level_votes: array of votes for each level
47 * @cur_level: the currently set voltage level
48 * @lock: lock to protect this struct
49 */
50struct clk_vdd_class {
51 const char *class_name;
52 int (*set_vdd)(struct clk_vdd_class *v_class, int level);
53 int level_votes[MAX_VDD_LEVELS];
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070054 unsigned long cur_level;
Matt Wagantalle18bbc82011-10-06 10:07:28 -070055 spinlock_t lock;
56};
57
58#define DEFINE_VDD_CLASS(_name, _set_vdd) \
59 struct clk_vdd_class _name = { \
60 .class_name = #_name, \
61 .set_vdd = _set_vdd, \
62 .cur_level = ARRAY_SIZE(_name.level_votes), \
63 .lock = __SPIN_LOCK_UNLOCKED(lock) \
64 }
65
Daniel Walker5e96da52010-05-12 13:43:28 -070066struct clk_ops {
Stephen Boyd3bbf3462012-01-12 00:19:23 -080067 int (*prepare)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068 int (*enable)(struct clk *clk);
69 void (*disable)(struct clk *clk);
Stephen Boyd3bbf3462012-01-12 00:19:23 -080070 void (*unprepare)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071 void (*auto_off)(struct clk *clk);
Stephen Boyda52d7e32011-11-10 11:59:00 -080072 void (*enable_hwcg)(struct clk *clk);
73 void (*disable_hwcg)(struct clk *clk);
74 int (*in_hwcg_mode)(struct clk *clk);
Matt Wagantall271a6cd2011-09-20 16:06:31 -070075 int (*handoff)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076 int (*reset)(struct clk *clk, enum clk_reset_action action);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070077 int (*set_rate)(struct clk *clk, unsigned long rate);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070078 int (*set_max_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070079 int (*set_flags)(struct clk *clk, unsigned flags);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070080 unsigned long (*get_rate)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081 int (*list_rate)(struct clk *clk, unsigned n);
82 int (*is_enabled)(struct clk *clk);
Matt Wagantall9de3bfb2011-11-03 20:13:12 -070083 long (*round_rate)(struct clk *clk, unsigned long rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 int (*set_parent)(struct clk *clk, struct clk *parent);
85 struct clk *(*get_parent)(struct clk *clk);
86 bool (*is_local)(struct clk *clk);
Daniel Walker5e96da52010-05-12 13:43:28 -070087};
Brian Swetland600f7cf2008-09-09 11:04:14 -070088
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089/**
90 * struct clk
Stephen Boyd3bbf3462012-01-12 00:19:23 -080091 * @prepare_count: prepare refcount
92 * @prepare_lock: protects clk_prepare()/clk_unprepare() path and @prepare_count
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093 * @count: enable refcount
94 * @lock: protects clk_enable()/clk_disable() path and @count
Stephen Boyd7fa26742011-08-11 23:22:29 -070095 * @depends: non-direct parent of clock to enable when this clock is enabled
Matt Wagantalle18bbc82011-10-06 10:07:28 -070096 * @vdd_class: voltage scaling requirement class
97 * @fmax: maximum frequency in Hz supported at each voltage level
Stephen Boyd3bbf3462012-01-12 00:19:23 -080098 * @warned: true if the clock has warned of incorrect usage, false otherwise
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099 */
Brian Swetland600f7cf2008-09-09 11:04:14 -0700100struct clk {
Brian Swetland600f7cf2008-09-09 11:04:14 -0700101 uint32_t flags;
Daniel Walker5e96da52010-05-12 13:43:28 -0700102 struct clk_ops *ops;
103 const char *dbg_name;
Stephen Boyd7fa26742011-08-11 23:22:29 -0700104 struct clk *depends;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700105 struct clk_vdd_class *vdd_class;
106 unsigned long fmax[MAX_VDD_LEVELS];
Matt Wagantall7205eea2011-11-04 17:31:29 -0700107 unsigned long rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108
109 struct list_head children;
110 struct list_head siblings;
111
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800112 bool warned;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113 unsigned count;
114 spinlock_t lock;
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800115 unsigned prepare_count;
116 struct mutex prepare_lock;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700117};
118
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119#define CLK_INIT(name) \
120 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
Stephen Boyd3bbf3462012-01-12 00:19:23 -0800121 .prepare_lock = __MUTEX_INITIALIZER((name).prepare_lock), \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122 .children = LIST_HEAD_INIT((name).children), \
123 .siblings = LIST_HEAD_INIT((name).siblings)
124
Stephen Boydbb600ae2011-08-02 20:11:40 -0700125/**
126 * struct clock_init_data - SoC specific clock initialization data
127 * @table: table of lookups to add
128 * @size: size of @table
129 * @init: called before registering @table
130 * @late_init: called during late init
131 */
132struct clock_init_data {
133 struct clk_lookup *table;
134 size_t size;
135 void (*init)(void);
136 int (*late_init)(void);
137};
138
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700139extern struct clock_init_data msm9615_clock_init_data;
Tianyi Gou41515e22011-09-01 19:37:43 -0700140extern struct clock_init_data apq8064_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700141extern struct clock_init_data apq8064_dummy_clock_init_data;
142extern struct clock_init_data fsm9xxx_clock_init_data;
143extern struct clock_init_data msm7x01a_clock_init_data;
144extern struct clock_init_data msm7x27_clock_init_data;
145extern struct clock_init_data msm7x27a_clock_init_data;
146extern struct clock_init_data msm7x30_clock_init_data;
147extern struct clock_init_data msm8960_clock_init_data;
148extern struct clock_init_data msm8960_dummy_clock_init_data;
149extern struct clock_init_data msm8x60_clock_init_data;
150extern struct clock_init_data qds8x50_clock_init_data;
Taniya Das7c9f0512011-12-02 14:26:46 +0530151extern struct clock_init_data msm8625_dummy_clock_init_data;
Tianyi Goue3d4f542012-03-15 17:06:45 -0700152extern struct clock_init_data msm8930_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700153
154void msm_clock_init(struct clock_init_data *data);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700155int vote_vdd_level(struct clk_vdd_class *vdd_class, int level);
156int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700157
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800158#ifdef CONFIG_DEBUG_FS
Stephen Boydbb600ae2011-08-02 20:11:40 -0700159int clock_debug_init(struct clock_init_data *data);
160int clock_debug_add(struct clk *clock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700161void clock_debug_print_enabled(void);
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800162#else
Stephen Boydbb600ae2011-08-02 20:11:40 -0700163static inline int clock_debug_init(struct clk_init_data *data) { return 0; }
164static inline int clock_debug_add(struct clk *clock) { return 0; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165static inline void clock_debug_print_enabled(void) { return; }
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800166#endif
167
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168extern struct clk dummy_clk;
169
170#define CLK_DUMMY(clk_name, clk_id, clk_dev, flags) { \
171 .con_id = clk_name, \
172 .dev_id = clk_dev, \
173 .clk = &dummy_clk, \
174 }
175
176#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
177
Brian Swetland600f7cf2008-09-09 11:04:14 -0700178#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179