blob: 9e3482b83aa97c61339ede5bbb3aeb0d4a2794a2 [file] [log] [blame]
Shashank Mittal30262902012-02-21 15:37:24 -08001/*
Duy Truongf3ac7b32013-02-13 01:07:28 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Shashank Mittal30262902012-02-21 15:37:24 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080011 * * Neither the name of The Linux Foundation nor
Shashank Mittal30262902012-02-21 15:37:24 -080012 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef CLOCK_H
30#define CLOCK_H
31
32#undef readl_relaxed
33#undef writel_relaxed
34
35#ifdef MSM_SECURE_IO
36#define readl_relaxed secure_readl
37#define writel_relaxed secure_writel
38#else
39#define readl_relaxed readl
40#define writel_relaxed writel
41#endif
42
43enum clk_reset_action {
44 CLK_RESET_DEASSERT = 0,
45 CLK_RESET_ASSERT = 1
46};
47
48struct clk;
49struct clk_ops {
50 int (*enable)(struct clk *clk);
51 void (*disable)(struct clk *clk);
52 void (*auto_off)(struct clk *clk);
53 int (*reset)(struct clk *clk, enum clk_reset_action action);
54 int (*set_rate)(struct clk *clk, unsigned rate);
55 int (*set_min_rate)(struct clk *clk, unsigned rate);
56 int (*set_max_rate)(struct clk *clk, unsigned rate);
57 int (*set_flags)(struct clk *clk, unsigned flags);
58 unsigned (*get_rate)(struct clk *clk);
59 int (*list_rate)(struct clk *clk, unsigned n);
60 int (*is_enabled)(struct clk *clk);
61 long (*round_rate)(struct clk *clk, unsigned rate);
62 int (*set_parent)(struct clk *clk, struct clk *parent);
63 struct clk *(*get_parent)(struct clk *clk);
64 bool (*is_local)(struct clk *clk);
65};
66
67/**
68 * struct clk
69 * @count: enable refcount
70 * @lock: protects clk_enable()/clk_disable() path and @count
71 */
72struct clk {
73 uint32_t flags;
Amol Jadi29f95032012-06-22 12:52:54 -070074 uint32_t rate;
Shashank Mittal30262902012-02-21 15:37:24 -080075 struct clk_ops *ops;
76 const char *dbg_name;
77 unsigned count;
78};
79
80/**
81 * clk_get - lookup and obtain a reference to a clock producer.
82 * @dev: device for clock "consumer"
83 * @id: clock comsumer ID
84 *
85 * Returns a struct clk corresponding to the clock producer, or
86 * valid IS_ERR() condition containing errno. The implementation
87 * uses @dev and @id to determine the clock consumer, and thereby
88 * the clock producer. (IOW, @id may be identical strings, but
89 * clk_get may return different clock producers depending on @dev.)
90 *
91 * Drivers must assume that the clock source is not enabled.
92 *
93 * clk_get should not be called from within interrupt context.
94 */
95struct clk *clk_get(const char *id);
96
97
98/**
99 * clk_enable - inform the system when the clock source should be running.
100 * @clk: clock source
101 *
102 * If the clock can not be enabled/disabled, this should return success.
103 *
104 * Returns success (0) or negative errno.
105 */
106int clk_enable(struct clk *clk);
107
108/**
109 * clk_disable - inform the system when the clock source is no longer required.
110 * @clk: clock source
111 *
112 * Inform the system that a clock source is no longer required by
113 * a driver and may be shut down.
114 *
115 * Implementation detail: if the clock source is shared between
116 * multiple drivers, clk_enable() calls must be balanced by the
117 * same number of clk_disable() calls for the clock source to be
118 * disabled.
119 */
120void clk_disable(struct clk *clk);
121
122/**
123 * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
124 * This is only valid once the clock source has been enabled.
125 * @clk: clock source
126 */
127unsigned long clk_get_rate(struct clk *clk);
128
129/**
130 * clk_set_rate - set the clock rate for a clock source
131 * @clk: clock source
132 * @rate: desired clock rate in Hz
133 *
134 * Returns success (0) or negative errno.
135 */
136int clk_set_rate(struct clk *clk, unsigned long rate);
137
138/**
139 * clk_set_parent - set the parent clock source for this clock
140 * @clk: clock source
141 * @parent: parent clock source
142 *
143 * Returns success (0) or negative errno.
144 */
145int clk_set_parent(struct clk *clk, struct clk *parent);
146
147/**
148 * clk_get_parent - get the parent clock source for this clock
149 * @clk: clock source
150 *
151 * Returns struct clk corresponding to parent clock source, or
152 * valid IS_ERR() condition containing errno.
153 */
154struct clk *clk_get_parent(struct clk *clk);
155
156/**
157 * clk_get_set_enable -
158 * -- get the clock.
159 * -- set the rate to @rate if @rate is non-zero
160 * -- enable the clock if @enable = ture;
161 * @id: clock identifier (char *)
162 * @rate: desired clock rate in Hz
163 *
164 * Returns success (0) or negative errno.
165 */
166int clk_get_set_enable(char *id, unsigned long rate, bool enable);
167
168struct clk_lookup {
169 const char *con_id;
170 struct clk *clk;
171};
172
173struct clk_list {
174 struct clk_lookup *clist;
175 unsigned num;
176};
177
178#define CLK_LOOKUP(con, c) { .con_id = con, .clk = &c }
179
180#ifdef DEBUG_CLOCK
181struct clk_list *clk_get_list(void);
182#endif
183
Amol Jadic2c941c2012-06-22 00:02:01 -0700184/**
185 * clk_init - register all the clocks in the system.
186 * @clist: pointer to clock list
187 * @num: number of clocks in the list
188 */
189void clk_init(struct clk_lookup *clist, unsigned num);
Shashank Mittal30262902012-02-21 15:37:24 -0800190#endif