Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
f8ce2547 | 2 | * linux/include/linux/clk.h |
1da177e4 LT |
3 | * |
4 | * Copyright (C) 2004 ARM Limited. | |
5 | * Written by Deep Blue Solutions Limited. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
686f8c5d TP |
11 | #ifndef __LINUX_CLK_H |
12 | #define __LINUX_CLK_H | |
1da177e4 LT |
13 | |
14 | struct device; | |
15 | ||
16 | /* | |
17 | * The base API. | |
18 | */ | |
19 | ||
20 | ||
21 | /* | |
22 | * struct clk - an machine class defined object / cookie. | |
23 | */ | |
24 | struct clk; | |
25 | ||
26 | /** | |
27 | * clk_get - lookup and obtain a reference to a clock producer. | |
28 | * @dev: device for clock "consumer" | |
ea3f4eac | 29 | * @id: clock comsumer ID |
1da177e4 LT |
30 | * |
31 | * Returns a struct clk corresponding to the clock producer, or | |
ea3f4eac RK |
32 | * valid IS_ERR() condition containing errno. The implementation |
33 | * uses @dev and @id to determine the clock consumer, and thereby | |
34 | * the clock producer. (IOW, @id may be identical strings, but | |
35 | * clk_get may return different clock producers depending on @dev.) | |
f47fc0ac RK |
36 | * |
37 | * Drivers must assume that the clock source is not enabled. | |
f7ad160b AR |
38 | * |
39 | * clk_get should not be called from within interrupt context. | |
1da177e4 LT |
40 | */ |
41 | struct clk *clk_get(struct device *dev, const char *id); | |
42 | ||
43 | /** | |
44 | * clk_enable - inform the system when the clock source should be running. | |
45 | * @clk: clock source | |
46 | * | |
47 | * If the clock can not be enabled/disabled, this should return success. | |
48 | * | |
49 | * Returns success (0) or negative errno. | |
50 | */ | |
51 | int clk_enable(struct clk *clk); | |
52 | ||
53 | /** | |
54 | * clk_disable - inform the system when the clock source is no longer required. | |
55 | * @clk: clock source | |
f47fc0ac RK |
56 | * |
57 | * Inform the system that a clock source is no longer required by | |
58 | * a driver and may be shut down. | |
59 | * | |
60 | * Implementation detail: if the clock source is shared between | |
61 | * multiple drivers, clk_enable() calls must be balanced by the | |
62 | * same number of clk_disable() calls for the clock source to be | |
63 | * disabled. | |
1da177e4 LT |
64 | */ |
65 | void clk_disable(struct clk *clk); | |
66 | ||
1da177e4 LT |
67 | /** |
68 | * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. | |
69 | * This is only valid once the clock source has been enabled. | |
70 | * @clk: clock source | |
71 | */ | |
72 | unsigned long clk_get_rate(struct clk *clk); | |
73 | ||
74 | /** | |
75 | * clk_put - "free" the clock source | |
76 | * @clk: clock source | |
f47fc0ac RK |
77 | * |
78 | * Note: drivers must ensure that all clk_enable calls made on this | |
79 | * clock source are balanced by clk_disable calls prior to calling | |
80 | * this function. | |
f7ad160b AR |
81 | * |
82 | * clk_put should not be called from within interrupt context. | |
1da177e4 LT |
83 | */ |
84 | void clk_put(struct clk *clk); | |
85 | ||
86 | ||
87 | /* | |
88 | * The remaining APIs are optional for machine class support. | |
89 | */ | |
90 | ||
91 | ||
92 | /** | |
93 | * clk_round_rate - adjust a rate to the exact rate a clock can provide | |
94 | * @clk: clock source | |
95 | * @rate: desired clock rate in Hz | |
96 | * | |
97 | * Returns rounded clock rate in Hz, or negative errno. | |
98 | */ | |
99 | long clk_round_rate(struct clk *clk, unsigned long rate); | |
100 | ||
101 | /** | |
102 | * clk_set_rate - set the clock rate for a clock source | |
103 | * @clk: clock source | |
104 | * @rate: desired clock rate in Hz | |
105 | * | |
106 | * Returns success (0) or negative errno. | |
107 | */ | |
108 | int clk_set_rate(struct clk *clk, unsigned long rate); | |
109 | ||
110 | /** | |
111 | * clk_set_parent - set the parent clock source for this clock | |
112 | * @clk: clock source | |
113 | * @parent: parent clock source | |
114 | * | |
115 | * Returns success (0) or negative errno. | |
116 | */ | |
117 | int clk_set_parent(struct clk *clk, struct clk *parent); | |
118 | ||
119 | /** | |
120 | * clk_get_parent - get the parent clock source for this clock | |
121 | * @clk: clock source | |
122 | * | |
123 | * Returns struct clk corresponding to parent clock source, or | |
124 | * valid IS_ERR() condition containing errno. | |
125 | */ | |
126 | struct clk *clk_get_parent(struct clk *clk); | |
127 | ||
05fd8e73 SH |
128 | /** |
129 | * clk_get_sys - get a clock based upon the device name | |
130 | * @dev_id: device name | |
131 | * @con_id: connection ID | |
132 | * | |
133 | * Returns a struct clk corresponding to the clock producer, or | |
134 | * valid IS_ERR() condition containing errno. The implementation | |
135 | * uses @dev_id and @con_id to determine the clock consumer, and | |
136 | * thereby the clock producer. In contrast to clk_get() this function | |
137 | * takes the device name instead of the device itself for identification. | |
138 | * | |
139 | * Drivers must assume that the clock source is not enabled. | |
140 | * | |
141 | * clk_get_sys should not be called from within interrupt context. | |
142 | */ | |
143 | struct clk *clk_get_sys(const char *dev_id, const char *con_id); | |
144 | ||
c0683039 TL |
145 | /** |
146 | * clk_add_alias - add a new clock alias | |
147 | * @alias: name for clock alias | |
148 | * @alias_dev_name: device name | |
149 | * @id: platform specific clock name | |
150 | * @dev: device | |
151 | * | |
152 | * Allows using generic clock names for drivers by adding a new alias. | |
153 | * Assumes clkdev, see clkdev.h for more info. | |
154 | */ | |
155 | int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, | |
156 | struct device *dev); | |
157 | ||
1da177e4 | 158 | #endif |