blob: ed5c9c6e250580d6d5f0f070356e4f616f5832c5 [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
Matt Wagantall22b0a792011-08-01 16:39:48 -070032#define CLKFLAG_SKIP_AUTO_OFF 0x00000200
Daniel Walker5e96da52010-05-12 13:43:28 -070033#define CLKFLAG_MIN 0x00000400
34#define CLKFLAG_MAX 0x00000800
35
Matt Wagantalle18bbc82011-10-06 10:07:28 -070036#define MAX_VDD_LEVELS 4
37
38/**
39 * struct clk_vdd_class - Voltage scaling class
40 * @class_name: name of the class
41 * @set_vdd: function to call when applying a new voltage setting
42 * @level_votes: array of votes for each level
43 * @cur_level: the currently set voltage level
44 * @lock: lock to protect this struct
45 */
46struct clk_vdd_class {
47 const char *class_name;
48 int (*set_vdd)(struct clk_vdd_class *v_class, int level);
49 int level_votes[MAX_VDD_LEVELS];
50 unsigned cur_level;
51 spinlock_t lock;
52};
53
54#define DEFINE_VDD_CLASS(_name, _set_vdd) \
55 struct clk_vdd_class _name = { \
56 .class_name = #_name, \
57 .set_vdd = _set_vdd, \
58 .cur_level = ARRAY_SIZE(_name.level_votes), \
59 .lock = __SPIN_LOCK_UNLOCKED(lock) \
60 }
61
Daniel Walker5e96da52010-05-12 13:43:28 -070062struct clk_ops {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063 int (*enable)(struct clk *clk);
64 void (*disable)(struct clk *clk);
65 void (*auto_off)(struct clk *clk);
Matt Wagantall271a6cd2011-09-20 16:06:31 -070066 int (*handoff)(struct clk *clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 int (*reset)(struct clk *clk, enum clk_reset_action action);
68 int (*set_rate)(struct clk *clk, unsigned rate);
69 int (*set_min_rate)(struct clk *clk, unsigned rate);
70 int (*set_max_rate)(struct clk *clk, unsigned rate);
71 int (*set_flags)(struct clk *clk, unsigned flags);
72 unsigned (*get_rate)(struct clk *clk);
73 int (*list_rate)(struct clk *clk, unsigned n);
74 int (*is_enabled)(struct clk *clk);
75 long (*round_rate)(struct clk *clk, unsigned rate);
76 int (*set_parent)(struct clk *clk, struct clk *parent);
77 struct clk *(*get_parent)(struct clk *clk);
78 bool (*is_local)(struct clk *clk);
Daniel Walker5e96da52010-05-12 13:43:28 -070079};
Brian Swetland600f7cf2008-09-09 11:04:14 -070080
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081/**
82 * struct clk
83 * @count: enable refcount
84 * @lock: protects clk_enable()/clk_disable() path and @count
Stephen Boyd7fa26742011-08-11 23:22:29 -070085 * @depends: non-direct parent of clock to enable when this clock is enabled
Matt Wagantalle18bbc82011-10-06 10:07:28 -070086 * @vdd_class: voltage scaling requirement class
87 * @fmax: maximum frequency in Hz supported at each voltage level
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088 */
Brian Swetland600f7cf2008-09-09 11:04:14 -070089struct clk {
Brian Swetland600f7cf2008-09-09 11:04:14 -070090 uint32_t flags;
Daniel Walker5e96da52010-05-12 13:43:28 -070091 struct clk_ops *ops;
92 const char *dbg_name;
Stephen Boyd7fa26742011-08-11 23:22:29 -070093 struct clk *depends;
Matt Wagantalle18bbc82011-10-06 10:07:28 -070094 struct clk_vdd_class *vdd_class;
95 unsigned long fmax[MAX_VDD_LEVELS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096
97 struct list_head children;
98 struct list_head siblings;
99
100 unsigned count;
101 spinlock_t lock;
Brian Swetland600f7cf2008-09-09 11:04:14 -0700102};
103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104#define CLK_INIT(name) \
105 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
106 .children = LIST_HEAD_INIT((name).children), \
107 .siblings = LIST_HEAD_INIT((name).siblings)
108
Stephen Boydbb600ae2011-08-02 20:11:40 -0700109/**
110 * struct clock_init_data - SoC specific clock initialization data
111 * @table: table of lookups to add
112 * @size: size of @table
113 * @init: called before registering @table
114 * @late_init: called during late init
115 */
116struct clock_init_data {
117 struct clk_lookup *table;
118 size_t size;
119 void (*init)(void);
120 int (*late_init)(void);
121};
122
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700123extern struct clock_init_data msm9615_clock_init_data;
Tianyi Gou41515e22011-09-01 19:37:43 -0700124extern struct clock_init_data apq8064_clock_init_data;
Stephen Boydbb600ae2011-08-02 20:11:40 -0700125extern struct clock_init_data apq8064_dummy_clock_init_data;
126extern struct clock_init_data fsm9xxx_clock_init_data;
127extern struct clock_init_data msm7x01a_clock_init_data;
128extern struct clock_init_data msm7x27_clock_init_data;
129extern struct clock_init_data msm7x27a_clock_init_data;
130extern struct clock_init_data msm7x30_clock_init_data;
131extern struct clock_init_data msm8960_clock_init_data;
132extern struct clock_init_data msm8960_dummy_clock_init_data;
133extern struct clock_init_data msm8x60_clock_init_data;
134extern struct clock_init_data qds8x50_clock_init_data;
135
136void msm_clock_init(struct clock_init_data *data);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700137int vote_vdd_level(struct clk_vdd_class *vdd_class, int level);
138int unvote_vdd_level(struct clk_vdd_class *vdd_class, int level);
Brian Swetland600f7cf2008-09-09 11:04:14 -0700139
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800140#ifdef CONFIG_DEBUG_FS
Stephen Boydbb600ae2011-08-02 20:11:40 -0700141int clock_debug_init(struct clock_init_data *data);
142int clock_debug_add(struct clk *clock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143void clock_debug_print_enabled(void);
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800144#else
Stephen Boydbb600ae2011-08-02 20:11:40 -0700145static inline int clock_debug_init(struct clk_init_data *data) { return 0; }
146static inline int clock_debug_add(struct clk *clock) { return 0; }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147static inline void clock_debug_print_enabled(void) { return; }
Matt Wagantalld64560fe2011-01-26 16:20:54 -0800148#endif
149
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150extern struct clk dummy_clk;
151
152#define CLK_DUMMY(clk_name, clk_id, clk_dev, flags) { \
153 .con_id = clk_name, \
154 .dev_id = clk_dev, \
155 .clk = &dummy_clk, \
156 }
157
158#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
159
Brian Swetland600f7cf2008-09-09 11:04:14 -0700160#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700161