Commit | Line | Data |
---|---|---|
571a354b LG |
1 | /* |
2 | * driver.h -- SoC Regulator driver support. | |
3 | * | |
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | |
5 | * | |
1dd68f01 | 6 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
571a354b LG |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | * | |
12 | * Regulator Driver Interface. | |
13 | */ | |
14 | ||
15 | #ifndef __LINUX_REGULATOR_DRIVER_H_ | |
16 | #define __LINUX_REGULATOR_DRIVER_H_ | |
17 | ||
18 | #include <linux/device.h> | |
ced55d4e | 19 | #include <linux/notifier.h> |
571a354b LG |
20 | #include <linux/regulator/consumer.h> |
21 | ||
65b19ce6 | 22 | struct regmap; |
571a354b | 23 | struct regulator_dev; |
a5766f11 | 24 | struct regulator_init_data; |
571a354b | 25 | |
853116a1 DB |
26 | enum regulator_status { |
27 | REGULATOR_STATUS_OFF, | |
28 | REGULATOR_STATUS_ON, | |
29 | REGULATOR_STATUS_ERROR, | |
30 | /* fast/normal/idle/standby are flavors of "on" */ | |
31 | REGULATOR_STATUS_FAST, | |
32 | REGULATOR_STATUS_NORMAL, | |
33 | REGULATOR_STATUS_IDLE, | |
34 | REGULATOR_STATUS_STANDBY, | |
35 | }; | |
36 | ||
571a354b LG |
37 | /** |
38 | * struct regulator_ops - regulator operations. | |
39 | * | |
3b2a6061 DB |
40 | * @enable: Configure the regulator as enabled. |
41 | * @disable: Configure the regulator as disabled. | |
d87b969d WS |
42 | * @is_enabled: Return 1 if the regulator is enabled, 0 if not. |
43 | * May also return negative errno. | |
c8e7e464 MB |
44 | * |
45 | * @set_voltage: Set the voltage for the regulator within the range specified. | |
46 | * The driver should select the voltage closest to min_uV. | |
e8eef82b MB |
47 | * @set_voltage_sel: Set the voltage for the regulator using the specified |
48 | * selector. | |
c8e7e464 | 49 | * @get_voltage: Return the currently configured voltage for the regulator. |
476c2d83 MB |
50 | * @get_voltage_sel: Return the currently configured voltage selector for the |
51 | * regulator. | |
4367cfdc DB |
52 | * @list_voltage: Return one of the supported voltages, in microvolts; zero |
53 | * if the selector indicates a voltage that is unusable on this system; | |
54 | * or negative errno. Selectors range from zero to one less than | |
55 | * regulator_desc.n_voltages. Voltages may be reported in any order. | |
c8e7e464 | 56 | * |
c8e7e464 | 57 | * @set_current_limit: Configure a limit for a current-limited regulator. |
3b2a6061 | 58 | * @get_current_limit: Get the configured limit for a current-limited regulator. |
c8e7e464 | 59 | * |
9f653251 | 60 | * @set_mode: Set the configured operating mode for the regulator. |
3b2a6061 DB |
61 | * @get_mode: Get the configured operating mode for the regulator. |
62 | * @get_status: Return actual (not as-configured) status of regulator, as a | |
63 | * REGULATOR_STATUS value (or negative errno) | |
c8e7e464 MB |
64 | * @get_optimum_mode: Get the most efficient operating mode for the regulator |
65 | * when running with the specified parameters. | |
66 | * | |
31aae2be | 67 | * @enable_time: Time taken for the regulator voltage output voltage to |
77af1b26 LW |
68 | * stabilise after being enabled, in microseconds. |
69 | * @set_voltage_time_sel: Time taken for the regulator voltage output voltage | |
70 | * to stabilise after being set to a new value, in microseconds. | |
71 | * The function provides the from and to voltage selector, the | |
72 | * function should return the worst case. | |
31aae2be | 73 | * |
c8e7e464 MB |
74 | * @set_suspend_voltage: Set the voltage for the regulator when the system |
75 | * is suspended. | |
76 | * @set_suspend_enable: Mark the regulator as enabled when the system is | |
77 | * suspended. | |
78 | * @set_suspend_disable: Mark the regulator as disabled when the system is | |
79 | * suspended. | |
80 | * @set_suspend_mode: Set the operating mode for the regulator when the | |
81 | * system is suspended. | |
3b2a6061 DB |
82 | * |
83 | * This struct describes regulator operations which can be implemented by | |
84 | * regulator chip drivers. | |
571a354b LG |
85 | */ |
86 | struct regulator_ops { | |
87 | ||
4367cfdc DB |
88 | /* enumerate supported voltages */ |
89 | int (*list_voltage) (struct regulator_dev *, unsigned selector); | |
90 | ||
571a354b | 91 | /* get/set regulator voltage */ |
3a93f2a9 MB |
92 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV, |
93 | unsigned *selector); | |
e8eef82b | 94 | int (*set_voltage_sel) (struct regulator_dev *, unsigned selector); |
571a354b | 95 | int (*get_voltage) (struct regulator_dev *); |
476c2d83 | 96 | int (*get_voltage_sel) (struct regulator_dev *); |
571a354b LG |
97 | |
98 | /* get/set regulator current */ | |
99 | int (*set_current_limit) (struct regulator_dev *, | |
100 | int min_uA, int max_uA); | |
101 | int (*get_current_limit) (struct regulator_dev *); | |
102 | ||
103 | /* enable/disable regulator */ | |
104 | int (*enable) (struct regulator_dev *); | |
105 | int (*disable) (struct regulator_dev *); | |
106 | int (*is_enabled) (struct regulator_dev *); | |
107 | ||
fde297bb | 108 | /* get/set regulator operating mode (defined in consumer.h) */ |
571a354b LG |
109 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
110 | unsigned int (*get_mode) (struct regulator_dev *); | |
111 | ||
77af1b26 | 112 | /* Time taken to enable or set voltage on the regulator */ |
31aae2be | 113 | int (*enable_time) (struct regulator_dev *); |
77af1b26 LW |
114 | int (*set_voltage_time_sel) (struct regulator_dev *, |
115 | unsigned int old_selector, | |
116 | unsigned int new_selector); | |
31aae2be | 117 | |
853116a1 DB |
118 | /* report regulator status ... most other accessors report |
119 | * control inputs, this reports results of combining inputs | |
120 | * from Linux (and other sources) with the actual load. | |
3b2a6061 | 121 | * returns REGULATOR_STATUS_* or negative errno. |
853116a1 DB |
122 | */ |
123 | int (*get_status)(struct regulator_dev *); | |
124 | ||
571a354b LG |
125 | /* get most efficient regulator operating mode for load */ |
126 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | |
127 | int output_uV, int load_uA); | |
128 | ||
129 | /* the operations below are for configuration of regulator state when | |
3de89609 | 130 | * its parent PMIC enters a global STANDBY/HIBERNATE state */ |
571a354b LG |
131 | |
132 | /* set regulator suspend voltage */ | |
133 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); | |
134 | ||
135 | /* enable/disable regulator in suspend state */ | |
136 | int (*set_suspend_enable) (struct regulator_dev *); | |
137 | int (*set_suspend_disable) (struct regulator_dev *); | |
138 | ||
fde297bb | 139 | /* set regulator suspend operating mode (defined in consumer.h) */ |
571a354b LG |
140 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); |
141 | }; | |
142 | ||
143 | /* | |
144 | * Regulators can either control voltage or current. | |
145 | */ | |
146 | enum regulator_type { | |
147 | REGULATOR_VOLTAGE, | |
148 | REGULATOR_CURRENT, | |
149 | }; | |
150 | ||
151 | /** | |
c172708d | 152 | * struct regulator_desc - Static regulator descriptor |
571a354b | 153 | * |
c172708d MB |
154 | * Each regulator registered with the core is described with a |
155 | * structure of this type and a struct regulator_config. This | |
156 | * structure contains the non-varying parts of the regulator | |
157 | * description. | |
c8e7e464 MB |
158 | * |
159 | * @name: Identifying name for the regulator. | |
69511a45 | 160 | * @supply_name: Identifying the regulator supply |
c8e7e464 | 161 | * @id: Numerical identifier for the regulator. |
4367cfdc | 162 | * @n_voltages: Number of selectors available for ops.list_voltage(). |
c8e7e464 | 163 | * @ops: Regulator operations table. |
0ba4887c | 164 | * @irq: Interrupt number for the regulator. |
c8e7e464 MB |
165 | * @type: Indicates if the regulator is a voltage or current regulator. |
166 | * @owner: Module providing the regulator, used for refcounting. | |
4ab5b3d9 MB |
167 | |
168 | * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ | |
169 | * @vsel_mask: Mask for register bitfield used for selector | |
cd6dffb4 MB |
170 | * @enable_reg: Register for control when using regmap enable/disable ops |
171 | * @enable_mask: Mask for control when using regmap enable/disable ops | |
571a354b LG |
172 | */ |
173 | struct regulator_desc { | |
174 | const char *name; | |
69511a45 | 175 | const char *supply_name; |
571a354b | 176 | int id; |
4367cfdc | 177 | unsigned n_voltages; |
571a354b LG |
178 | struct regulator_ops *ops; |
179 | int irq; | |
180 | enum regulator_type type; | |
181 | struct module *owner; | |
4ab5b3d9 MB |
182 | |
183 | unsigned int vsel_reg; | |
184 | unsigned int vsel_mask; | |
cd6dffb4 MB |
185 | unsigned int enable_reg; |
186 | unsigned int enable_mask; | |
571a354b LG |
187 | }; |
188 | ||
c172708d MB |
189 | /** |
190 | * struct regulator_config - Dynamic regulator descriptor | |
191 | * | |
192 | * Each regulator registered with the core is described with a | |
193 | * structure of this type and a struct regulator_desc. This structure | |
194 | * contains the runtime variable parts of the regulator description. | |
195 | * | |
196 | * @dev: struct device for the regulator | |
197 | * @init_data: platform provided init data, passed through by driver | |
198 | * @driver_data: private regulator data | |
199 | * @of_node: OpenFirmware node to parse for device tree bindings (may be | |
200 | * NULL). | |
65b19ce6 | 201 | * @regmap: regmap to use for core regmap helpers |
c172708d MB |
202 | */ |
203 | struct regulator_config { | |
204 | struct device *dev; | |
205 | const struct regulator_init_data *init_data; | |
206 | void *driver_data; | |
207 | struct device_node *of_node; | |
65b19ce6 | 208 | struct regmap *regmap; |
c172708d MB |
209 | }; |
210 | ||
1fa9ad52 MB |
211 | /* |
212 | * struct regulator_dev | |
213 | * | |
214 | * Voltage / Current regulator class device. One for each | |
215 | * regulator. | |
216 | * | |
217 | * This should *not* be used directly by anything except the regulator | |
218 | * core and notification injection (which should take the mutex and do | |
219 | * no other direct access). | |
220 | */ | |
221 | struct regulator_dev { | |
65f26846 | 222 | const struct regulator_desc *desc; |
5ffbd136 | 223 | int exclusive; |
1130e5b3 MB |
224 | u32 use_count; |
225 | u32 open_count; | |
1fa9ad52 MB |
226 | |
227 | /* lists we belong to */ | |
228 | struct list_head list; /* list of all regulators */ | |
1fa9ad52 MB |
229 | |
230 | /* lists we own */ | |
231 | struct list_head consumer_list; /* consumers we supply */ | |
1fa9ad52 MB |
232 | |
233 | struct blocking_notifier_head notifier; | |
234 | struct mutex mutex; /* consumer lock */ | |
235 | struct module *owner; | |
236 | struct device dev; | |
237 | struct regulation_constraints *constraints; | |
3801b86a | 238 | struct regulator *supply; /* for tree */ |
65b19ce6 | 239 | struct regmap *regmap; |
1fa9ad52 | 240 | |
da07ecd9 MB |
241 | struct delayed_work disable_work; |
242 | int deferred_disables; | |
243 | ||
1fa9ad52 | 244 | void *reg_data; /* regulator_dev data */ |
1130e5b3 | 245 | |
1130e5b3 | 246 | struct dentry *debugfs; |
1fa9ad52 MB |
247 | }; |
248 | ||
65f26846 MB |
249 | struct regulator_dev * |
250 | regulator_register(const struct regulator_desc *regulator_desc, | |
c172708d | 251 | const struct regulator_config *config); |
571a354b LG |
252 | void regulator_unregister(struct regulator_dev *rdev); |
253 | ||
254 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | |
255 | unsigned long event, void *data); | |
256 | ||
257 | void *rdev_get_drvdata(struct regulator_dev *rdev); | |
a5766f11 | 258 | struct device *rdev_get_dev(struct regulator_dev *rdev); |
571a354b LG |
259 | int rdev_get_id(struct regulator_dev *rdev); |
260 | ||
be721979 MB |
261 | int regulator_mode_to_status(unsigned int); |
262 | ||
4ab5b3d9 MB |
263 | int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); |
264 | int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); | |
cd6dffb4 MB |
265 | int regulator_is_enabled_regmap(struct regulator_dev *rdev); |
266 | int regulator_enable_regmap(struct regulator_dev *rdev); | |
267 | int regulator_disable_regmap(struct regulator_dev *rdev); | |
4ab5b3d9 | 268 | |
a5766f11 LG |
269 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); |
270 | ||
571a354b | 271 | #endif |