Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 2 | * linux/include/linux/clk.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Todd Poynor | 686f8c5 | 2006-03-25 18:15:24 +0000 | [diff] [blame] | 11 | #ifndef __LINUX_CLK_H |
| 12 | #define __LINUX_CLK_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Russell King | 40d3e0f | 2011-09-22 11:30:50 +0100 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | struct device; |
| 17 | |
| 18 | /* |
| 19 | * The base API. |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | /* |
| 24 | * struct clk - an machine class defined object / cookie. |
| 25 | */ |
| 26 | struct clk; |
| 27 | |
| 28 | /** |
| 29 | * clk_get - lookup and obtain a reference to a clock producer. |
| 30 | * @dev: device for clock "consumer" |
Russell King | ea3f4ea | 2005-04-27 18:19:55 +0100 | [diff] [blame] | 31 | * @id: clock comsumer ID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * |
| 33 | * Returns a struct clk corresponding to the clock producer, or |
Russell King | ea3f4ea | 2005-04-27 18:19:55 +0100 | [diff] [blame] | 34 | * valid IS_ERR() condition containing errno. The implementation |
| 35 | * uses @dev and @id to determine the clock consumer, and thereby |
| 36 | * the clock producer. (IOW, @id may be identical strings, but |
| 37 | * clk_get may return different clock producers depending on @dev.) |
Russell King | f47fc0a | 2006-01-03 18:34:20 +0000 | [diff] [blame] | 38 | * |
| 39 | * Drivers must assume that the clock source is not enabled. |
Alex Raimondi | f7ad160 | 2008-10-15 22:02:03 -0700 | [diff] [blame] | 40 | * |
| 41 | * clk_get should not be called from within interrupt context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | */ |
| 43 | struct clk *clk_get(struct device *dev, const char *id); |
| 44 | |
| 45 | /** |
Russell King | 40d3e0f | 2011-09-22 11:30:50 +0100 | [diff] [blame] | 46 | * clk_prepare - prepare a clock source |
| 47 | * @clk: clock source |
| 48 | * |
| 49 | * This prepares the clock source for use. |
| 50 | * |
| 51 | * Must not be called from within atomic context. |
| 52 | */ |
| 53 | #ifdef CONFIG_HAVE_CLK_PREPARE |
| 54 | int clk_prepare(struct clk *clk); |
| 55 | #else |
| 56 | static inline int clk_prepare(struct clk *clk) |
| 57 | { |
| 58 | might_sleep(); |
| 59 | return 0; |
| 60 | } |
| 61 | #endif |
| 62 | |
| 63 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * clk_enable - inform the system when the clock source should be running. |
| 65 | * @clk: clock source |
| 66 | * |
| 67 | * If the clock can not be enabled/disabled, this should return success. |
| 68 | * |
Russell King | 40d3e0f | 2011-09-22 11:30:50 +0100 | [diff] [blame] | 69 | * May be called from atomic contexts. |
| 70 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * Returns success (0) or negative errno. |
| 72 | */ |
| 73 | int clk_enable(struct clk *clk); |
| 74 | |
| 75 | /** |
| 76 | * clk_disable - inform the system when the clock source is no longer required. |
| 77 | * @clk: clock source |
Russell King | f47fc0a | 2006-01-03 18:34:20 +0000 | [diff] [blame] | 78 | * |
| 79 | * Inform the system that a clock source is no longer required by |
| 80 | * a driver and may be shut down. |
| 81 | * |
Russell King | 40d3e0f | 2011-09-22 11:30:50 +0100 | [diff] [blame] | 82 | * May be called from atomic contexts. |
| 83 | * |
Russell King | f47fc0a | 2006-01-03 18:34:20 +0000 | [diff] [blame] | 84 | * Implementation detail: if the clock source is shared between |
| 85 | * multiple drivers, clk_enable() calls must be balanced by the |
| 86 | * same number of clk_disable() calls for the clock source to be |
| 87 | * disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | */ |
| 89 | void clk_disable(struct clk *clk); |
| 90 | |
Russell King | 40d3e0f | 2011-09-22 11:30:50 +0100 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * clk_unprepare - undo preparation of a clock source |
| 94 | * @clk: clock source |
| 95 | * |
| 96 | * This undoes a previously prepared clock. The caller must balance |
| 97 | * the number of prepare and unprepare calls. |
| 98 | * |
| 99 | * Must not be called from within atomic context. |
| 100 | */ |
| 101 | #ifdef CONFIG_HAVE_CLK_PREPARE |
| 102 | void clk_unprepare(struct clk *clk); |
| 103 | #else |
| 104 | static inline void clk_unprepare(struct clk *clk) |
| 105 | { |
| 106 | might_sleep(); |
| 107 | } |
| 108 | #endif |
| 109 | |
Richard Zhao | 42c5d52 | 2011-11-15 14:47:56 +0800 | [diff] [blame] | 110 | /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */ |
| 111 | static inline int clk_prepare_enable(struct clk *clk) |
| 112 | { |
| 113 | int ret; |
| 114 | |
| 115 | ret = clk_prepare(clk); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | ret = clk_enable(clk); |
| 119 | if (ret) |
| 120 | clk_unprepare(clk); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | /* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */ |
| 126 | static inline void clk_disable_unprepare(struct clk *clk) |
| 127 | { |
| 128 | clk_disable(clk); |
| 129 | clk_unprepare(clk); |
| 130 | } |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. |
| 134 | * This is only valid once the clock source has been enabled. |
| 135 | * @clk: clock source |
| 136 | */ |
| 137 | unsigned long clk_get_rate(struct clk *clk); |
| 138 | |
| 139 | /** |
| 140 | * clk_put - "free" the clock source |
| 141 | * @clk: clock source |
Russell King | f47fc0a | 2006-01-03 18:34:20 +0000 | [diff] [blame] | 142 | * |
| 143 | * Note: drivers must ensure that all clk_enable calls made on this |
| 144 | * clock source are balanced by clk_disable calls prior to calling |
| 145 | * this function. |
Alex Raimondi | f7ad160 | 2008-10-15 22:02:03 -0700 | [diff] [blame] | 146 | * |
| 147 | * clk_put should not be called from within interrupt context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | */ |
| 149 | void clk_put(struct clk *clk); |
| 150 | |
| 151 | |
| 152 | /* |
| 153 | * The remaining APIs are optional for machine class support. |
| 154 | */ |
| 155 | |
| 156 | |
| 157 | /** |
| 158 | * clk_round_rate - adjust a rate to the exact rate a clock can provide |
| 159 | * @clk: clock source |
| 160 | * @rate: desired clock rate in Hz |
| 161 | * |
| 162 | * Returns rounded clock rate in Hz, or negative errno. |
| 163 | */ |
| 164 | long clk_round_rate(struct clk *clk, unsigned long rate); |
| 165 | |
| 166 | /** |
| 167 | * clk_set_rate - set the clock rate for a clock source |
| 168 | * @clk: clock source |
| 169 | * @rate: desired clock rate in Hz |
| 170 | * |
| 171 | * Returns success (0) or negative errno. |
| 172 | */ |
| 173 | int clk_set_rate(struct clk *clk, unsigned long rate); |
| 174 | |
| 175 | /** |
| 176 | * clk_set_parent - set the parent clock source for this clock |
| 177 | * @clk: clock source |
| 178 | * @parent: parent clock source |
| 179 | * |
| 180 | * Returns success (0) or negative errno. |
| 181 | */ |
| 182 | int clk_set_parent(struct clk *clk, struct clk *parent); |
| 183 | |
| 184 | /** |
| 185 | * clk_get_parent - get the parent clock source for this clock |
| 186 | * @clk: clock source |
| 187 | * |
| 188 | * Returns struct clk corresponding to parent clock source, or |
| 189 | * valid IS_ERR() condition containing errno. |
| 190 | */ |
| 191 | struct clk *clk_get_parent(struct clk *clk); |
| 192 | |
Sascha Hauer | 05fd8e7 | 2009-03-07 12:55:49 +0100 | [diff] [blame] | 193 | /** |
| 194 | * clk_get_sys - get a clock based upon the device name |
| 195 | * @dev_id: device name |
| 196 | * @con_id: connection ID |
| 197 | * |
| 198 | * Returns a struct clk corresponding to the clock producer, or |
| 199 | * valid IS_ERR() condition containing errno. The implementation |
| 200 | * uses @dev_id and @con_id to determine the clock consumer, and |
| 201 | * thereby the clock producer. In contrast to clk_get() this function |
| 202 | * takes the device name instead of the device itself for identification. |
| 203 | * |
| 204 | * Drivers must assume that the clock source is not enabled. |
| 205 | * |
| 206 | * clk_get_sys should not be called from within interrupt context. |
| 207 | */ |
| 208 | struct clk *clk_get_sys(const char *dev_id, const char *con_id); |
| 209 | |
Tony Lindgren | c068303 | 2009-06-03 17:43:14 +0100 | [diff] [blame] | 210 | /** |
| 211 | * clk_add_alias - add a new clock alias |
| 212 | * @alias: name for clock alias |
| 213 | * @alias_dev_name: device name |
| 214 | * @id: platform specific clock name |
| 215 | * @dev: device |
| 216 | * |
| 217 | * Allows using generic clock names for drivers by adding a new alias. |
| 218 | * Assumes clkdev, see clkdev.h for more info. |
| 219 | */ |
| 220 | int clk_add_alias(const char *alias, const char *alias_dev_name, char *id, |
| 221 | struct device *dev); |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | #endif |