blob: 1054c033e783ac4de92e83b62d99ee8fdb4c4d9a [file] [log] [blame]
Liam Girdwood571a3542008-04-30 15:42:28 +01001/*
2 * driver.h -- SoC Regulator driver support.
3 *
4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
5 *
Liam Girdwood1dd68f02009-02-02 21:43:31 +00006 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood571a3542008-04-30 15:42:28 +01007 *
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>
Paul Gortmakerced55d42011-07-17 16:24:35 -040019#include <linux/notifier.h>
Liam Girdwood571a3542008-04-30 15:42:28 +010020#include <linux/regulator/consumer.h>
21
Mark Brown65b19ce2012-04-15 11:16:05 +010022struct regmap;
Liam Girdwood571a3542008-04-30 15:42:28 +010023struct regulator_dev;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +010024struct regulator_config;
Liam Girdwooda5766f12008-10-10 13:22:20 +010025struct regulator_init_data;
Kim, Milof19b00d2013-02-18 06:50:39 +000026struct regulator_enable_gpio;
Liam Girdwood571a3542008-04-30 15:42:28 +010027
David Brownell853116a2009-01-14 23:03:17 -080028enum regulator_status {
29 REGULATOR_STATUS_OFF,
30 REGULATOR_STATUS_ON,
31 REGULATOR_STATUS_ERROR,
32 /* fast/normal/idle/standby are flavors of "on" */
33 REGULATOR_STATUS_FAST,
34 REGULATOR_STATUS_NORMAL,
35 REGULATOR_STATUS_IDLE,
36 REGULATOR_STATUS_STANDBY,
Mark Brownf59c8f92012-08-31 10:36:37 -070037 /* The regulator is enabled but not regulating */
38 REGULATOR_STATUS_BYPASS,
Krystian Garbaciak1beaf762012-07-12 13:53:35 +010039 /* in case that any other status doesn't apply */
40 REGULATOR_STATUS_UNDEFINED,
David Brownell853116a2009-01-14 23:03:17 -080041};
42
Liam Girdwood571a3542008-04-30 15:42:28 +010043/**
Randy Dunlap7c2330f2013-09-16 18:08:02 -070044 * struct regulator_linear_range - specify linear voltage ranges
45 *
Mark Brown94d33c02013-07-02 22:52:41 +010046 * Specify a range of voltages for regulator_map_linar_range() and
47 * regulator_list_linear_range().
48 *
49 * @min_uV: Lowest voltage in range
Mark Brown94d33c02013-07-02 22:52:41 +010050 * @min_sel: Lowest selector for range
51 * @max_sel: Highest selector for range
52 * @uV_step: Step size
53 */
54struct regulator_linear_range {
55 unsigned int min_uV;
Mark Brown94d33c02013-07-02 22:52:41 +010056 unsigned int min_sel;
57 unsigned int max_sel;
58 unsigned int uV_step;
59};
60
Axel Lin8828bae2013-10-11 09:32:18 +080061/* Initialize struct regulator_linear_range */
62#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
63{ \
64 .min_uV = _min_uV, \
65 .min_sel = _min_sel, \
66 .max_sel = _max_sel, \
67 .uV_step = _step_uV, \
68}
69
Mark Brown94d33c02013-07-02 22:52:41 +010070/**
Liam Girdwood571a3542008-04-30 15:42:28 +010071 * struct regulator_ops - regulator operations.
72 *
David Brownell3b2a6062009-02-26 13:28:41 -080073 * @enable: Configure the regulator as enabled.
74 * @disable: Configure the regulator as disabled.
Wolfram Sangd87b9692009-09-18 22:44:46 +020075 * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
76 * May also return negative errno.
Mark Brownc8e7e462008-12-31 12:52:42 +000077 *
78 * @set_voltage: Set the voltage for the regulator within the range specified.
79 * The driver should select the voltage closest to min_uV.
Mark Browne8eef822010-12-12 14:36:17 +000080 * @set_voltage_sel: Set the voltage for the regulator using the specified
81 * selector.
Mark Browne843fc42012-05-09 21:16:06 +010082 * @map_voltage: Convert a voltage into a selector
Mark Brownc8e7e462008-12-31 12:52:42 +000083 * @get_voltage: Return the currently configured voltage for the regulator.
Mark Brown476c2d82010-12-10 17:28:07 +000084 * @get_voltage_sel: Return the currently configured voltage selector for the
85 * regulator.
David Brownell4367cfd2009-02-26 11:48:36 -080086 * @list_voltage: Return one of the supported voltages, in microvolts; zero
87 * if the selector indicates a voltage that is unusable on this system;
88 * or negative errno. Selectors range from zero to one less than
89 * regulator_desc.n_voltages. Voltages may be reported in any order.
Mark Brownc8e7e462008-12-31 12:52:42 +000090 *
Mark Brownc8e7e462008-12-31 12:52:42 +000091 * @set_current_limit: Configure a limit for a current-limited regulator.
Axel Lin89009e12012-08-08 20:17:18 +080092 * The driver should select the current closest to max_uA.
David Brownell3b2a6062009-02-26 13:28:41 -080093 * @get_current_limit: Get the configured limit for a current-limited regulator.
Stephen Boyd36e4f832015-06-11 17:37:06 -070094 * @set_input_current_limit: Configure an input limit.
Mark Brownc8e7e462008-12-31 12:52:42 +000095 *
Luis de Bethencourtabf2f822016-03-23 11:35:39 +000096 * @set_over_current_protection: Support capability of automatically shutting
97 * down when detecting an over current event.
98 *
Laxman Dewangan670666b2016-03-02 16:24:46 +053099 * @set_active_discharge: Set active discharge enable/disable of regulators.
100 *
Randy Dunlap9f6532512009-04-03 21:31:30 -0700101 * @set_mode: Set the configured operating mode for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800102 * @get_mode: Get the configured operating mode for the regulator.
Axel Haslam1b5b4222016-11-03 12:11:42 +0100103 * @get_error_flags: Get the current error(s) for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800104 * @get_status: Return actual (not as-configured) status of regulator, as a
105 * REGULATOR_STATUS value (or negative errno)
Mark Brownc8e7e462008-12-31 12:52:42 +0000106 * @get_optimum_mode: Get the most efficient operating mode for the regulator
107 * when running with the specified parameters.
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800108 * @set_load: Set the load for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000109 *
Mark Brownf59c8f92012-08-31 10:36:37 -0700110 * @set_bypass: Set the regulator in bypass mode.
111 * @get_bypass: Get the regulator bypass mode state.
112 *
Mark Brown31aae2b2009-12-21 12:21:52 +0000113 * @enable_time: Time taken for the regulator voltage output voltage to
Linus Walleij77af1b22011-03-17 13:24:36 +0100114 * stabilise after being enabled, in microseconds.
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530115 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
116 * select ramp delay equal to or less than(closest) ramp_delay.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700117 * @set_voltage_time: Time taken for the regulator voltage output voltage
118 * to stabilise after being set to a new value, in microseconds.
119 * The function receives the from and to voltage as input, it
120 * should return the worst case.
Linus Walleij77af1b22011-03-17 13:24:36 +0100121 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
122 * to stabilise after being set to a new value, in microseconds.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700123 * The function receives the from and to voltage selector as
124 * input, it should return the worst case.
Stephen Boydc751ad02015-06-12 15:48:06 -0700125 * @set_soft_start: Enable soft start for the regulator.
Mark Brown31aae2b2009-12-21 12:21:52 +0000126 *
Mark Brownc8e7e462008-12-31 12:52:42 +0000127 * @set_suspend_voltage: Set the voltage for the regulator when the system
128 * is suspended.
129 * @set_suspend_enable: Mark the regulator as enabled when the system is
130 * suspended.
131 * @set_suspend_disable: Mark the regulator as disabled when the system is
132 * suspended.
133 * @set_suspend_mode: Set the operating mode for the regulator when the
134 * system is suspended.
David Brownell3b2a6062009-02-26 13:28:41 -0800135 *
Stephen Boyd23c779b2015-06-11 17:37:04 -0700136 * @set_pull_down: Configure the regulator to pull down when the regulator
137 * is disabled.
138 *
David Brownell3b2a6062009-02-26 13:28:41 -0800139 * This struct describes regulator operations which can be implemented by
140 * regulator chip drivers.
Liam Girdwood571a3542008-04-30 15:42:28 +0100141 */
142struct regulator_ops {
143
David Brownell4367cfd2009-02-26 11:48:36 -0800144 /* enumerate supported voltages */
145 int (*list_voltage) (struct regulator_dev *, unsigned selector);
146
Liam Girdwood571a3542008-04-30 15:42:28 +0100147 /* get/set regulator voltage */
Mark Brown3a93f2a2010-11-10 14:38:29 +0000148 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
149 unsigned *selector);
Mark Browne843fc42012-05-09 21:16:06 +0100150 int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
Mark Browne8eef822010-12-12 14:36:17 +0000151 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100152 int (*get_voltage) (struct regulator_dev *);
Mark Brown476c2d82010-12-10 17:28:07 +0000153 int (*get_voltage_sel) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100154
155 /* get/set regulator current */
156 int (*set_current_limit) (struct regulator_dev *,
157 int min_uA, int max_uA);
158 int (*get_current_limit) (struct regulator_dev *);
159
Stephen Boyd36e4f832015-06-11 17:37:06 -0700160 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
Stephen Boyd3a003ba2015-07-17 14:41:54 -0700161 int (*set_over_current_protection) (struct regulator_dev *);
Laxman Dewangan670666b2016-03-02 16:24:46 +0530162 int (*set_active_discharge) (struct regulator_dev *, bool enable);
Stephen Boyd36e4f832015-06-11 17:37:06 -0700163
Liam Girdwood571a3542008-04-30 15:42:28 +0100164 /* enable/disable regulator */
165 int (*enable) (struct regulator_dev *);
166 int (*disable) (struct regulator_dev *);
167 int (*is_enabled) (struct regulator_dev *);
168
Kim, Milofde297bb2012-02-16 22:41:32 -0800169 /* get/set regulator operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100170 int (*set_mode) (struct regulator_dev *, unsigned int mode);
171 unsigned int (*get_mode) (struct regulator_dev *);
172
Axel Haslam1b5b4222016-11-03 12:11:42 +0100173 /* retrieve current error flags on the regulator */
174 int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
175
Linus Walleij77af1b22011-03-17 13:24:36 +0100176 /* Time taken to enable or set voltage on the regulator */
Mark Brown31aae2b2009-12-21 12:21:52 +0000177 int (*enable_time) (struct regulator_dev *);
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530178 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700179 int (*set_voltage_time) (struct regulator_dev *, int old_uV,
180 int new_uV);
Linus Walleij77af1b22011-03-17 13:24:36 +0100181 int (*set_voltage_time_sel) (struct regulator_dev *,
182 unsigned int old_selector,
183 unsigned int new_selector);
Mark Brown31aae2b2009-12-21 12:21:52 +0000184
Stephen Boyd57f66b72015-06-11 17:37:05 -0700185 int (*set_soft_start) (struct regulator_dev *);
186
David Brownell853116a2009-01-14 23:03:17 -0800187 /* report regulator status ... most other accessors report
188 * control inputs, this reports results of combining inputs
189 * from Linux (and other sources) with the actual load.
David Brownell3b2a6062009-02-26 13:28:41 -0800190 * returns REGULATOR_STATUS_* or negative errno.
David Brownell853116a2009-01-14 23:03:17 -0800191 */
192 int (*get_status)(struct regulator_dev *);
193
Liam Girdwood571a3542008-04-30 15:42:28 +0100194 /* get most efficient regulator operating mode for load */
195 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
196 int output_uV, int load_uA);
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800197 /* set the load on the regulator */
198 int (*set_load)(struct regulator_dev *, int load_uA);
Liam Girdwood571a3542008-04-30 15:42:28 +0100199
Mark Brownf59c8f92012-08-31 10:36:37 -0700200 /* control and report on bypass mode */
201 int (*set_bypass)(struct regulator_dev *dev, bool enable);
202 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
203
Liam Girdwood571a3542008-04-30 15:42:28 +0100204 /* the operations below are for configuration of regulator state when
Mark Brown3de89602008-09-09 16:21:17 +0100205 * its parent PMIC enters a global STANDBY/HIBERNATE state */
Liam Girdwood571a3542008-04-30 15:42:28 +0100206
207 /* set regulator suspend voltage */
208 int (*set_suspend_voltage) (struct regulator_dev *, int uV);
209
210 /* enable/disable regulator in suspend state */
211 int (*set_suspend_enable) (struct regulator_dev *);
212 int (*set_suspend_disable) (struct regulator_dev *);
213
Kim, Milofde297bb2012-02-16 22:41:32 -0800214 /* set regulator suspend operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100215 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
Stephen Boyd23c779b2015-06-11 17:37:04 -0700216
217 int (*set_pull_down) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100218};
219
220/*
221 * Regulators can either control voltage or current.
222 */
223enum regulator_type {
224 REGULATOR_VOLTAGE,
225 REGULATOR_CURRENT,
226};
227
228/**
Mark Brownc1727082012-04-04 00:50:22 +0100229 * struct regulator_desc - Static regulator descriptor
Liam Girdwood571a3542008-04-30 15:42:28 +0100230 *
Mark Brownc1727082012-04-04 00:50:22 +0100231 * Each regulator registered with the core is described with a
232 * structure of this type and a struct regulator_config. This
233 * structure contains the non-varying parts of the regulator
234 * description.
Mark Brownc8e7e462008-12-31 12:52:42 +0000235 *
236 * @name: Identifying name for the regulator.
Rajendra Nayak69511a42011-11-18 16:47:20 +0530237 * @supply_name: Identifying the regulator supply
Mark Browna0c7b162014-09-09 23:13:57 +0100238 * @of_match: Name used to identify regulator in DT.
239 * @regulators_node: Name of node containing regulator definitions in DT.
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100240 * @of_parse_cb: Optional callback called only if of_match is present.
241 * Will be called for each regulator parsed from DT, during
242 * init_data parsing.
243 * The regulator_config passed as argument to the callback will
244 * be a copy of config passed to regulator_register, valid only
245 * for this particular call. Callback may freely change the
246 * config but it cannot store it for later usage.
247 * Callback should return 0 on success or negative ERRNO
248 * indicating failure.
Mark Brownc8e7e462008-12-31 12:52:42 +0000249 * @id: Numerical identifier for the regulator.
250 * @ops: Regulator operations table.
Randy Dunlap0ba48872009-01-08 11:50:23 -0800251 * @irq: Interrupt number for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000252 * @type: Indicates if the regulator is a voltage or current regulator.
253 * @owner: Module providing the regulator, used for refcounting.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100254 *
Pawel Mollbd7a2b62012-09-24 18:56:53 +0100255 * @continuous_voltage_range: Indicates if the regulator can set any
256 * voltage within constrains range.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100257 * @n_voltages: Number of selectors available for ops.list_voltage().
258 *
259 * @min_uV: Voltage given by the lowest selector (if linear mapping)
260 * @uV_step: Voltage increase with each selector (if linear mapping)
Axel Lin33234e72012-11-27 10:24:33 +0800261 * @linear_min_sel: Minimal selector for starting linear mapping
Laxman Dewangan5a523602013-09-10 15:45:05 +0530262 * @fixed_uV: Fixed voltage of rails.
Axel Linea38d132012-06-18 14:03:16 +0800263 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200264 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700265 * @linear_ranges: A constant table of possible voltage ranges.
266 * @n_linear_ranges: Number of entries in the @linear_ranges table.
Axel Lincffc9592012-05-20 10:30:21 +0800267 * @volt_table: Voltage mapping table (if table based mapping)
Mark Brownbca7bbf2012-05-09 21:38:33 +0100268 *
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100269 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
270 * @vsel_mask: Mask for register bitfield used for selector
Luis de Bethencourtd13d3a52016-03-23 11:24:47 +0000271 * @csel_reg: Register for TPS65218 LS3 current regulator
272 * @csel_mask: Mask for TPS65218 LS3 current regulator
Axel Linc8520b42012-12-18 09:30:10 +0800273 * @apply_reg: Register for initiate voltage change on the output when
274 * using regulator_set_voltage_sel_regmap
275 * @apply_bit: Register bitfield used for initiate voltage change on the
276 * output when using regulator_set_voltage_sel_regmap
Mark Browncd6dffb2012-04-15 12:37:47 +0100277 * @enable_reg: Register for control when using regmap enable/disable ops
278 * @enable_mask: Mask for control when using regmap enable/disable ops
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100279 * @enable_val: Enabling value for control when using regmap enable/disable ops
280 * @disable_val: Disabling value for control when using regmap enable/disable ops
Axel Lin51dcdaf2013-03-05 14:16:00 +0800281 * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
282 * when using regulator_enable_regmap and friends APIs.
Nishanth Menon5838b032013-02-28 18:12:47 -0600283 * @bypass_reg: Register for control when using regmap set_bypass
284 * @bypass_mask: Mask for control when using regmap set_bypass
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100285 * @bypass_val_on: Enabling value for control when using regmap set_bypass
286 * @bypass_val_off: Disabling value for control when using regmap set_bypass
Laxman Dewangan354794d2016-03-02 16:24:47 +0530287 * @active_discharge_off: Enabling value for control when using regmap
288 * set_active_discharge
289 * @active_discharge_on: Disabling value for control when using regmap
290 * set_active_discharge
291 * @active_discharge_mask: Mask for control when using regmap
292 * set_active_discharge
293 * @active_discharge_reg: Register for control when using regmap
294 * set_active_discharge
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100295 * @soft_start_reg: Register for control when using regmap set_soft_start
296 * @soft_start_mask: Mask for control when using regmap set_soft_start
297 * @soft_start_val_on: Enabling value for control when using regmap
298 * set_soft_start
Mark Brown79511ed2012-06-27 14:23:10 +0100299 *
300 * @enable_time: Time taken for initial enable of regulator (in uS).
Guodong Xu871f5652014-08-13 19:33:40 +0800301 * @off_on_delay: guard time (in uS), before re-enabling a regulator
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100302 *
303 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
Liam Girdwood571a3542008-04-30 15:42:28 +0100304 */
305struct regulator_desc {
306 const char *name;
Rajendra Nayak69511a42011-11-18 16:47:20 +0530307 const char *supply_name;
Mark Browna0c7b162014-09-09 23:13:57 +0100308 const char *of_match;
309 const char *regulators_node;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100310 int (*of_parse_cb)(struct device_node *,
311 const struct regulator_desc *,
312 struct regulator_config *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100313 int id;
Mark Brownde4a54c2016-01-21 20:19:41 +0000314 unsigned int continuous_voltage_range:1;
David Brownell4367cfd2009-02-26 11:48:36 -0800315 unsigned n_voltages;
Axel Lindf11e502014-08-21 10:11:34 +0800316 const struct regulator_ops *ops;
Liam Girdwood571a3542008-04-30 15:42:28 +0100317 int irq;
318 enum regulator_type type;
319 struct module *owner;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100320
Mark Brownbca7bbf2012-05-09 21:38:33 +0100321 unsigned int min_uV;
322 unsigned int uV_step;
Axel Lin33234e72012-11-27 10:24:33 +0800323 unsigned int linear_min_sel;
Laxman Dewangan5a523602013-09-10 15:45:05 +0530324 int fixed_uV;
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530325 unsigned int ramp_delay;
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200326 int min_dropout_uV;
Mark Brownbca7bbf2012-05-09 21:38:33 +0100327
Mark Brown94d33c02013-07-02 22:52:41 +0100328 const struct regulator_linear_range *linear_ranges;
329 int n_linear_ranges;
330
Axel Lincffc9592012-05-20 10:30:21 +0800331 const unsigned int *volt_table;
332
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100333 unsigned int vsel_reg;
334 unsigned int vsel_mask;
Nikita Kiryanovc0ea88b2015-11-25 13:59:04 +0200335 unsigned int csel_reg;
336 unsigned int csel_mask;
Axel Linc8520b42012-12-18 09:30:10 +0800337 unsigned int apply_reg;
338 unsigned int apply_bit;
Mark Browncd6dffb2012-04-15 12:37:47 +0100339 unsigned int enable_reg;
340 unsigned int enable_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100341 unsigned int enable_val;
342 unsigned int disable_val;
Axel Lin51dcdaf2013-03-05 14:16:00 +0800343 bool enable_is_inverted;
Mark Browndf367932012-08-27 16:04:23 -0700344 unsigned int bypass_reg;
345 unsigned int bypass_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100346 unsigned int bypass_val_on;
347 unsigned int bypass_val_off;
Laxman Dewangan354794d2016-03-02 16:24:47 +0530348 unsigned int active_discharge_on;
349 unsigned int active_discharge_off;
350 unsigned int active_discharge_mask;
351 unsigned int active_discharge_reg;
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100352 unsigned int soft_start_reg;
353 unsigned int soft_start_mask;
354 unsigned int soft_start_val_on;
Mark Brown79511ed2012-06-27 14:23:10 +0100355
356 unsigned int enable_time;
Guodong Xu871f5652014-08-13 19:33:40 +0800357
358 unsigned int off_on_delay;
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100359
360 unsigned int (*of_map_mode)(unsigned int mode);
Liam Girdwood571a3542008-04-30 15:42:28 +0100361};
362
Mark Brownc1727082012-04-04 00:50:22 +0100363/**
364 * struct regulator_config - Dynamic regulator descriptor
365 *
366 * Each regulator registered with the core is described with a
367 * structure of this type and a struct regulator_desc. This structure
368 * contains the runtime variable parts of the regulator description.
369 *
370 * @dev: struct device for the regulator
371 * @init_data: platform provided init data, passed through by driver
372 * @driver_data: private regulator data
373 * @of_node: OpenFirmware node to parse for device tree bindings (may be
374 * NULL).
Axel Lincf392842015-03-18 08:57:41 +0800375 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
Mark Brown380a0e62012-08-31 10:31:53 -0700376 * insufficient.
Markus Pargmann76f439d2014-10-08 15:47:05 +0200377 * @ena_gpio_initialized: GPIO controlling regulator enable was properly
378 * initialized, meaning that >= 0 is a valid gpio
379 * identifier and < 0 is a non existent gpio.
Mark Brown65f73502012-06-27 14:14:38 +0100380 * @ena_gpio: GPIO controlling regulator enable.
381 * @ena_gpio_invert: Sense for GPIO enable control.
382 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
Mark Brownc1727082012-04-04 00:50:22 +0100383 */
384struct regulator_config {
385 struct device *dev;
386 const struct regulator_init_data *init_data;
387 void *driver_data;
388 struct device_node *of_node;
Mark Brown65b19ce2012-04-15 11:16:05 +0100389 struct regmap *regmap;
Mark Brown65f73502012-06-27 14:14:38 +0100390
Markus Pargmann76f439d2014-10-08 15:47:05 +0200391 bool ena_gpio_initialized;
Mark Brown65f73502012-06-27 14:14:38 +0100392 int ena_gpio;
393 unsigned int ena_gpio_invert:1;
394 unsigned int ena_gpio_flags;
Mark Brownc1727082012-04-04 00:50:22 +0100395};
396
Mark Brown1fa9ad52009-01-21 14:08:40 +0000397/*
398 * struct regulator_dev
399 *
400 * Voltage / Current regulator class device. One for each
401 * regulator.
402 *
403 * This should *not* be used directly by anything except the regulator
404 * core and notification injection (which should take the mutex and do
405 * no other direct access).
406 */
407struct regulator_dev {
Mark Brown65f26842012-04-03 20:46:53 +0100408 const struct regulator_desc *desc;
Mark Brown5ffbd132009-07-21 16:00:23 +0100409 int exclusive;
Mark Brown1130e5b2010-12-21 23:49:31 +0000410 u32 use_count;
411 u32 open_count;
Mark Brownf59c8f92012-08-31 10:36:37 -0700412 u32 bypass_count;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000413
414 /* lists we belong to */
415 struct list_head list; /* list of all regulators */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000416
417 /* lists we own */
418 struct list_head consumer_list; /* consumers we supply */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000419
420 struct blocking_notifier_head notifier;
421 struct mutex mutex; /* consumer lock */
422 struct module *owner;
423 struct device dev;
424 struct regulation_constraints *constraints;
Mark Brown3801b862011-06-09 16:22:22 +0100425 struct regulator *supply; /* for tree */
Bjorn Andersson6261b062015-03-24 18:56:05 -0700426 const char *supply_name;
Mark Brown65b19ce2012-04-15 11:16:05 +0100427 struct regmap *regmap;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000428
Mark Brownda07ecd2011-09-11 09:53:50 +0100429 struct delayed_work disable_work;
430 int deferred_disables;
431
Mark Brown1fa9ad52009-01-21 14:08:40 +0000432 void *reg_data; /* regulator_dev data */
Mark Brown1130e5b2010-12-21 23:49:31 +0000433
Mark Brown1130e5b2010-12-21 23:49:31 +0000434 struct dentry *debugfs;
Mark Brown65f73502012-06-27 14:14:38 +0100435
Kim, Milof19b00d2013-02-18 06:50:39 +0000436 struct regulator_enable_gpio *ena_pin;
Mark Brown65f73502012-06-27 14:14:38 +0100437 unsigned int ena_gpio_state:1;
Guodong Xu871f5652014-08-13 19:33:40 +0800438
439 /* time when this regulator was disabled last time */
440 unsigned long last_off_jiffy;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000441};
442
Mark Brown65f26842012-04-03 20:46:53 +0100443struct regulator_dev *
444regulator_register(const struct regulator_desc *regulator_desc,
Mark Brownc1727082012-04-04 00:50:22 +0100445 const struct regulator_config *config);
Mark Brownb33e46b2013-08-31 11:58:26 +0100446struct regulator_dev *
447devm_regulator_register(struct device *dev,
448 const struct regulator_desc *regulator_desc,
449 const struct regulator_config *config);
Liam Girdwood571a3542008-04-30 15:42:28 +0100450void regulator_unregister(struct regulator_dev *rdev);
Mark Brownb33e46b2013-08-31 11:58:26 +0100451void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100452
453int regulator_notifier_call_chain(struct regulator_dev *rdev,
454 unsigned long event, void *data);
455
456void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100457struct device *rdev_get_dev(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100458int rdev_get_id(struct regulator_dev *rdev);
459
Mark Brownbe721972009-08-04 20:09:52 +0200460int regulator_mode_to_status(unsigned int);
461
Mark Brownbca7bbf2012-05-09 21:38:33 +0100462int regulator_list_voltage_linear(struct regulator_dev *rdev,
463 unsigned int selector);
Mark Brown94d33c02013-07-02 22:52:41 +0100464int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
465 unsigned int selector);
Axel Lincffc9592012-05-20 10:30:21 +0800466int regulator_list_voltage_table(struct regulator_dev *rdev,
467 unsigned int selector);
Mark Brownbca7bbf2012-05-09 21:38:33 +0100468int regulator_map_voltage_linear(struct regulator_dev *rdev,
469 int min_uV, int max_uV);
Mark Brown94d33c02013-07-02 22:52:41 +0100470int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
471 int min_uV, int max_uV);
Mark Browne843fc42012-05-09 21:16:06 +0100472int regulator_map_voltage_iterate(struct regulator_dev *rdev,
473 int min_uV, int max_uV);
Axel Linfcf371e2013-04-18 10:34:49 +0800474int regulator_map_voltage_ascend(struct regulator_dev *rdev,
475 int min_uV, int max_uV);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100476int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
477int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
Mark Browncd6dffb2012-04-15 12:37:47 +0100478int regulator_is_enabled_regmap(struct regulator_dev *rdev);
479int regulator_enable_regmap(struct regulator_dev *rdev);
480int regulator_disable_regmap(struct regulator_dev *rdev);
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530481int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
482 unsigned int old_selector,
483 unsigned int new_selector);
Mark Browndf367932012-08-27 16:04:23 -0700484int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
485int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100486int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100487
Laxman Dewangan354794d2016-03-02 16:24:47 +0530488int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
489 bool enable);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100490void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
491
Liam Girdwood571a3542008-04-30 15:42:28 +0100492#endif