blob: d45ab52c91c9a583bca831fb10f26b9438332b15 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Liam Girdwood571a3542008-04-30 15:42:28 +01002/*
3 * driver.h -- SoC Regulator driver support.
4 *
5 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6 *
Liam Girdwood1dd68f02009-02-02 21:43:31 +00007 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood571a3542008-04-30 15:42:28 +01008 *
Liam Girdwood571a3542008-04-30 15:42:28 +01009 * Regulator Driver Interface.
10 */
11
12#ifndef __LINUX_REGULATOR_DRIVER_H_
13#define __LINUX_REGULATOR_DRIVER_H_
14
Dmitry Osipenko40c223e2018-10-05 18:36:33 +030015#define MAX_COUPLED 2
Maciej Purskia085a312018-04-23 16:33:39 +020016
Liam Girdwood571a3542008-04-30 15:42:28 +010017#include <linux/device.h>
Paul Gortmakerced55d42011-07-17 16:24:35 -040018#include <linux/notifier.h>
Liam Girdwood571a3542008-04-30 15:42:28 +010019#include <linux/regulator/consumer.h>
Dmitry Osipenkof8702f92018-11-19 00:56:17 +030020#include <linux/ww_mutex.h>
Liam Girdwood571a3542008-04-30 15:42:28 +010021
Linus Walleije45e2902018-02-12 14:16:57 +010022struct gpio_desc;
Mark Brown65b19ce2012-04-15 11:16:05 +010023struct regmap;
Liam Girdwood571a3542008-04-30 15:42:28 +010024struct regulator_dev;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +010025struct regulator_config;
Liam Girdwooda5766f12008-10-10 13:22:20 +010026struct regulator_init_data;
Kim, Milof19b00d2013-02-18 06:50:39 +000027struct regulator_enable_gpio;
Liam Girdwood571a3542008-04-30 15:42:28 +010028
David Brownell853116a2009-01-14 23:03:17 -080029enum regulator_status {
30 REGULATOR_STATUS_OFF,
31 REGULATOR_STATUS_ON,
32 REGULATOR_STATUS_ERROR,
33 /* fast/normal/idle/standby are flavors of "on" */
34 REGULATOR_STATUS_FAST,
35 REGULATOR_STATUS_NORMAL,
36 REGULATOR_STATUS_IDLE,
37 REGULATOR_STATUS_STANDBY,
Mark Brownf59c8f92012-08-31 10:36:37 -070038 /* The regulator is enabled but not regulating */
39 REGULATOR_STATUS_BYPASS,
Krystian Garbaciak1beaf762012-07-12 13:53:35 +010040 /* in case that any other status doesn't apply */
41 REGULATOR_STATUS_UNDEFINED,
David Brownell853116a2009-01-14 23:03:17 -080042};
43
Liam Girdwood571a3542008-04-30 15:42:28 +010044/**
Randy Dunlap7c2330f2013-09-16 18:08:02 -070045 * struct regulator_linear_range - specify linear voltage ranges
46 *
Matthias Kaehlcke7bd0c7b2018-06-07 16:51:38 -070047 * Specify a range of voltages for regulator_map_linear_range() and
Mark Brown94d33c02013-07-02 22:52:41 +010048 * regulator_list_linear_range().
49 *
50 * @min_uV: Lowest voltage in range
Mark Brown94d33c02013-07-02 22:52:41 +010051 * @min_sel: Lowest selector for range
52 * @max_sel: Highest selector for range
53 * @uV_step: Step size
54 */
55struct regulator_linear_range {
56 unsigned int min_uV;
Mark Brown94d33c02013-07-02 22:52:41 +010057 unsigned int min_sel;
58 unsigned int max_sel;
59 unsigned int uV_step;
60};
61
Axel Lin8828bae2013-10-11 09:32:18 +080062/* Initialize struct regulator_linear_range */
63#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
64{ \
65 .min_uV = _min_uV, \
66 .min_sel = _min_sel, \
67 .max_sel = _max_sel, \
68 .uV_step = _step_uV, \
69}
70
Mark Brown94d33c02013-07-02 22:52:41 +010071/**
Liam Girdwood571a3542008-04-30 15:42:28 +010072 * struct regulator_ops - regulator operations.
73 *
David Brownell3b2a6062009-02-26 13:28:41 -080074 * @enable: Configure the regulator as enabled.
75 * @disable: Configure the regulator as disabled.
Wolfram Sangd87b9692009-09-18 22:44:46 +020076 * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
77 * May also return negative errno.
Mark Brownc8e7e462008-12-31 12:52:42 +000078 *
79 * @set_voltage: Set the voltage for the regulator within the range specified.
80 * The driver should select the voltage closest to min_uV.
Mark Browne8eef822010-12-12 14:36:17 +000081 * @set_voltage_sel: Set the voltage for the regulator using the specified
82 * selector.
Mark Browne843fc42012-05-09 21:16:06 +010083 * @map_voltage: Convert a voltage into a selector
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070084 * @get_voltage: Return the currently configured voltage for the regulator;
85 * return -ENOTRECOVERABLE if regulator can't be read at
86 * bootup and hasn't been set yet.
Mark Brown476c2d82010-12-10 17:28:07 +000087 * @get_voltage_sel: Return the currently configured voltage selector for the
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070088 * regulator; return -ENOTRECOVERABLE if regulator can't
89 * be read at bootup and hasn't been set yet.
David Brownell4367cfd2009-02-26 11:48:36 -080090 * @list_voltage: Return one of the supported voltages, in microvolts; zero
91 * if the selector indicates a voltage that is unusable on this system;
92 * or negative errno. Selectors range from zero to one less than
93 * regulator_desc.n_voltages. Voltages may be reported in any order.
Mark Brownc8e7e462008-12-31 12:52:42 +000094 *
Mark Brownc8e7e462008-12-31 12:52:42 +000095 * @set_current_limit: Configure a limit for a current-limited regulator.
Axel Lin89009e12012-08-08 20:17:18 +080096 * The driver should select the current closest to max_uA.
David Brownell3b2a6062009-02-26 13:28:41 -080097 * @get_current_limit: Get the configured limit for a current-limited regulator.
Stephen Boyd36e4f832015-06-11 17:37:06 -070098 * @set_input_current_limit: Configure an input limit.
Mark Brownc8e7e462008-12-31 12:52:42 +000099 *
Luis de Bethencourtabf2f822016-03-23 11:35:39 +0000100 * @set_over_current_protection: Support capability of automatically shutting
101 * down when detecting an over current event.
102 *
Laxman Dewangan670666b2016-03-02 16:24:46 +0530103 * @set_active_discharge: Set active discharge enable/disable of regulators.
104 *
Randy Dunlap9f6532512009-04-03 21:31:30 -0700105 * @set_mode: Set the configured operating mode for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800106 * @get_mode: Get the configured operating mode for the regulator.
Axel Haslam1b5b4222016-11-03 12:11:42 +0100107 * @get_error_flags: Get the current error(s) for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800108 * @get_status: Return actual (not as-configured) status of regulator, as a
109 * REGULATOR_STATUS value (or negative errno)
Mark Brownc8e7e462008-12-31 12:52:42 +0000110 * @get_optimum_mode: Get the most efficient operating mode for the regulator
111 * when running with the specified parameters.
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800112 * @set_load: Set the load for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000113 *
Mark Brownf59c8f92012-08-31 10:36:37 -0700114 * @set_bypass: Set the regulator in bypass mode.
115 * @get_bypass: Get the regulator bypass mode state.
116 *
Mark Brown31aae2b2009-12-21 12:21:52 +0000117 * @enable_time: Time taken for the regulator voltage output voltage to
Linus Walleij77af1b22011-03-17 13:24:36 +0100118 * stabilise after being enabled, in microseconds.
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530119 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
120 * select ramp delay equal to or less than(closest) ramp_delay.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700121 * @set_voltage_time: Time taken for the regulator voltage output voltage
122 * to stabilise after being set to a new value, in microseconds.
123 * The function receives the from and to voltage as input, it
124 * should return the worst case.
Linus Walleij77af1b22011-03-17 13:24:36 +0100125 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
126 * to stabilise after being set to a new value, in microseconds.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700127 * The function receives the from and to voltage selector as
128 * input, it should return the worst case.
Stephen Boydc751ad02015-06-12 15:48:06 -0700129 * @set_soft_start: Enable soft start for the regulator.
Mark Brown31aae2b2009-12-21 12:21:52 +0000130 *
Mark Brownc8e7e462008-12-31 12:52:42 +0000131 * @set_suspend_voltage: Set the voltage for the regulator when the system
132 * is suspended.
133 * @set_suspend_enable: Mark the regulator as enabled when the system is
134 * suspended.
135 * @set_suspend_disable: Mark the regulator as disabled when the system is
136 * suspended.
137 * @set_suspend_mode: Set the operating mode for the regulator when the
138 * system is suspended.
David Brownell3b2a6062009-02-26 13:28:41 -0800139 *
Stephen Boyd23c779b2015-06-11 17:37:04 -0700140 * @set_pull_down: Configure the regulator to pull down when the regulator
141 * is disabled.
142 *
David Brownell3b2a6062009-02-26 13:28:41 -0800143 * This struct describes regulator operations which can be implemented by
144 * regulator chip drivers.
Liam Girdwood571a3542008-04-30 15:42:28 +0100145 */
146struct regulator_ops {
147
David Brownell4367cfd2009-02-26 11:48:36 -0800148 /* enumerate supported voltages */
149 int (*list_voltage) (struct regulator_dev *, unsigned selector);
150
Liam Girdwood571a3542008-04-30 15:42:28 +0100151 /* get/set regulator voltage */
Mark Brown3a93f2a2010-11-10 14:38:29 +0000152 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
153 unsigned *selector);
Mark Browne843fc42012-05-09 21:16:06 +0100154 int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
Mark Browne8eef822010-12-12 14:36:17 +0000155 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100156 int (*get_voltage) (struct regulator_dev *);
Mark Brown476c2d82010-12-10 17:28:07 +0000157 int (*get_voltage_sel) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100158
159 /* get/set regulator current */
160 int (*set_current_limit) (struct regulator_dev *,
161 int min_uA, int max_uA);
162 int (*get_current_limit) (struct regulator_dev *);
163
Stephen Boyd36e4f832015-06-11 17:37:06 -0700164 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
Stephen Boyd3a003ba2015-07-17 14:41:54 -0700165 int (*set_over_current_protection) (struct regulator_dev *);
Laxman Dewangan670666b2016-03-02 16:24:46 +0530166 int (*set_active_discharge) (struct regulator_dev *, bool enable);
Stephen Boyd36e4f832015-06-11 17:37:06 -0700167
Liam Girdwood571a3542008-04-30 15:42:28 +0100168 /* enable/disable regulator */
169 int (*enable) (struct regulator_dev *);
170 int (*disable) (struct regulator_dev *);
171 int (*is_enabled) (struct regulator_dev *);
172
Kim, Milofde297bb2012-02-16 22:41:32 -0800173 /* get/set regulator operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100174 int (*set_mode) (struct regulator_dev *, unsigned int mode);
175 unsigned int (*get_mode) (struct regulator_dev *);
176
Axel Haslam1b5b4222016-11-03 12:11:42 +0100177 /* retrieve current error flags on the regulator */
178 int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
179
Linus Walleij77af1b22011-03-17 13:24:36 +0100180 /* Time taken to enable or set voltage on the regulator */
Mark Brown31aae2b2009-12-21 12:21:52 +0000181 int (*enable_time) (struct regulator_dev *);
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530182 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700183 int (*set_voltage_time) (struct regulator_dev *, int old_uV,
184 int new_uV);
Linus Walleij77af1b22011-03-17 13:24:36 +0100185 int (*set_voltage_time_sel) (struct regulator_dev *,
186 unsigned int old_selector,
187 unsigned int new_selector);
Mark Brown31aae2b2009-12-21 12:21:52 +0000188
Stephen Boyd57f66b72015-06-11 17:37:05 -0700189 int (*set_soft_start) (struct regulator_dev *);
190
David Brownell853116a2009-01-14 23:03:17 -0800191 /* report regulator status ... most other accessors report
192 * control inputs, this reports results of combining inputs
193 * from Linux (and other sources) with the actual load.
David Brownell3b2a6062009-02-26 13:28:41 -0800194 * returns REGULATOR_STATUS_* or negative errno.
David Brownell853116a2009-01-14 23:03:17 -0800195 */
196 int (*get_status)(struct regulator_dev *);
197
Liam Girdwood571a3542008-04-30 15:42:28 +0100198 /* get most efficient regulator operating mode for load */
199 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
200 int output_uV, int load_uA);
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800201 /* set the load on the regulator */
202 int (*set_load)(struct regulator_dev *, int load_uA);
Liam Girdwood571a3542008-04-30 15:42:28 +0100203
Mark Brownf59c8f92012-08-31 10:36:37 -0700204 /* control and report on bypass mode */
205 int (*set_bypass)(struct regulator_dev *dev, bool enable);
206 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
207
Liam Girdwood571a3542008-04-30 15:42:28 +0100208 /* the operations below are for configuration of regulator state when
Mark Brown3de89602008-09-09 16:21:17 +0100209 * its parent PMIC enters a global STANDBY/HIBERNATE state */
Liam Girdwood571a3542008-04-30 15:42:28 +0100210
211 /* set regulator suspend voltage */
212 int (*set_suspend_voltage) (struct regulator_dev *, int uV);
213
214 /* enable/disable regulator in suspend state */
215 int (*set_suspend_enable) (struct regulator_dev *);
216 int (*set_suspend_disable) (struct regulator_dev *);
217
Kim, Milofde297bb2012-02-16 22:41:32 -0800218 /* set regulator suspend operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100219 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
Stephen Boyd23c779b2015-06-11 17:37:04 -0700220
pascal paillet0380cf72018-07-05 14:25:57 +0000221 int (*resume)(struct regulator_dev *rdev);
Chunyan Zhangf7efad12018-01-26 21:08:47 +0800222
Stephen Boyd23c779b2015-06-11 17:37:04 -0700223 int (*set_pull_down) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100224};
225
226/*
227 * Regulators can either control voltage or current.
228 */
229enum regulator_type {
230 REGULATOR_VOLTAGE,
231 REGULATOR_CURRENT,
232};
233
234/**
Mark Brownc1727082012-04-04 00:50:22 +0100235 * struct regulator_desc - Static regulator descriptor
Liam Girdwood571a3542008-04-30 15:42:28 +0100236 *
Mark Brownc1727082012-04-04 00:50:22 +0100237 * Each regulator registered with the core is described with a
238 * structure of this type and a struct regulator_config. This
239 * structure contains the non-varying parts of the regulator
240 * description.
Mark Brownc8e7e462008-12-31 12:52:42 +0000241 *
242 * @name: Identifying name for the regulator.
Rajendra Nayak69511a42011-11-18 16:47:20 +0530243 * @supply_name: Identifying the regulator supply
Mark Browna0c7b162014-09-09 23:13:57 +0100244 * @of_match: Name used to identify regulator in DT.
245 * @regulators_node: Name of node containing regulator definitions in DT.
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100246 * @of_parse_cb: Optional callback called only if of_match is present.
247 * Will be called for each regulator parsed from DT, during
248 * init_data parsing.
249 * The regulator_config passed as argument to the callback will
250 * be a copy of config passed to regulator_register, valid only
251 * for this particular call. Callback may freely change the
252 * config but it cannot store it for later usage.
253 * Callback should return 0 on success or negative ERRNO
254 * indicating failure.
Mark Brownc8e7e462008-12-31 12:52:42 +0000255 * @id: Numerical identifier for the regulator.
256 * @ops: Regulator operations table.
Randy Dunlap0ba48872009-01-08 11:50:23 -0800257 * @irq: Interrupt number for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000258 * @type: Indicates if the regulator is a voltage or current regulator.
259 * @owner: Module providing the regulator, used for refcounting.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100260 *
Pawel Mollbd7a2b62012-09-24 18:56:53 +0100261 * @continuous_voltage_range: Indicates if the regulator can set any
262 * voltage within constrains range.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100263 * @n_voltages: Number of selectors available for ops.list_voltage().
Axel Lina32e0c72019-02-28 21:40:13 +0800264 * @n_current_limits: Number of selectors available for current limits
Mark Brownbca7bbf2012-05-09 21:38:33 +0100265 *
266 * @min_uV: Voltage given by the lowest selector (if linear mapping)
267 * @uV_step: Voltage increase with each selector (if linear mapping)
Axel Lin33234e72012-11-27 10:24:33 +0800268 * @linear_min_sel: Minimal selector for starting linear mapping
Laxman Dewangan5a523602013-09-10 15:45:05 +0530269 * @fixed_uV: Fixed voltage of rails.
Axel Linea38d132012-06-18 14:03:16 +0800270 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200271 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700272 * @linear_ranges: A constant table of possible voltage ranges.
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300273 * @linear_range_selectors: A constant table of voltage range selectors.
274 * If pickable ranges are used each range must
275 * have corresponding selector here.
276 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
277 * linear_range_selectors if used) table(s).
Axel Lincffc9592012-05-20 10:30:21 +0800278 * @volt_table: Voltage mapping table (if table based mapping)
Axel Lina32e0c72019-02-28 21:40:13 +0800279 * @curr_table: Current limit mapping table (if table based mapping)
Mark Brownbca7bbf2012-05-09 21:38:33 +0100280 *
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300281 * @vsel_range_reg: Register for range selector when using pickable ranges
282 * and regulator_regmap_X_voltage_X_pickable functions.
283 * @vsel_range_mask: Mask for register bitfield used for range selector
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100284 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
285 * @vsel_mask: Mask for register bitfield used for selector
Axel Lin35d838f2019-02-28 21:40:12 +0800286 * @csel_reg: Register for current limit selector using regmap set_current_limit
287 * @csel_mask: Mask for register bitfield used for current limit selector
Axel Linc8520b42012-12-18 09:30:10 +0800288 * @apply_reg: Register for initiate voltage change on the output when
289 * using regulator_set_voltage_sel_regmap
290 * @apply_bit: Register bitfield used for initiate voltage change on the
291 * output when using regulator_set_voltage_sel_regmap
Mark Browncd6dffb2012-04-15 12:37:47 +0100292 * @enable_reg: Register for control when using regmap enable/disable ops
293 * @enable_mask: Mask for control when using regmap enable/disable ops
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100294 * @enable_val: Enabling value for control when using regmap enable/disable ops
295 * @disable_val: Disabling value for control when using regmap enable/disable ops
Axel Lin51dcdaf2013-03-05 14:16:00 +0800296 * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
297 * when using regulator_enable_regmap and friends APIs.
Nishanth Menon5838b032013-02-28 18:12:47 -0600298 * @bypass_reg: Register for control when using regmap set_bypass
299 * @bypass_mask: Mask for control when using regmap set_bypass
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100300 * @bypass_val_on: Enabling value for control when using regmap set_bypass
301 * @bypass_val_off: Disabling value for control when using regmap set_bypass
Laxman Dewangan354794d2016-03-02 16:24:47 +0530302 * @active_discharge_off: Enabling value for control when using regmap
303 * set_active_discharge
304 * @active_discharge_on: Disabling value for control when using regmap
305 * set_active_discharge
306 * @active_discharge_mask: Mask for control when using regmap
307 * set_active_discharge
308 * @active_discharge_reg: Register for control when using regmap
309 * set_active_discharge
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100310 * @soft_start_reg: Register for control when using regmap set_soft_start
311 * @soft_start_mask: Mask for control when using regmap set_soft_start
312 * @soft_start_val_on: Enabling value for control when using regmap
313 * set_soft_start
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100314 * @pull_down_reg: Register for control when using regmap set_pull_down
315 * @pull_down_mask: Mask for control when using regmap set_pull_down
316 * @pull_down_val_on: Enabling value for control when using regmap
317 * set_pull_down
Mark Brown79511ed2012-06-27 14:23:10 +0100318 *
319 * @enable_time: Time taken for initial enable of regulator (in uS).
Guodong Xu871f5652014-08-13 19:33:40 +0800320 * @off_on_delay: guard time (in uS), before re-enabling a regulator
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100321 *
322 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
Liam Girdwood571a3542008-04-30 15:42:28 +0100323 */
324struct regulator_desc {
325 const char *name;
Rajendra Nayak69511a42011-11-18 16:47:20 +0530326 const char *supply_name;
Mark Browna0c7b162014-09-09 23:13:57 +0100327 const char *of_match;
328 const char *regulators_node;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100329 int (*of_parse_cb)(struct device_node *,
330 const struct regulator_desc *,
331 struct regulator_config *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100332 int id;
Mark Brownde4a54c2016-01-21 20:19:41 +0000333 unsigned int continuous_voltage_range:1;
David Brownell4367cfd2009-02-26 11:48:36 -0800334 unsigned n_voltages;
Axel Lina32e0c72019-02-28 21:40:13 +0800335 unsigned int n_current_limits;
Axel Lindf11e502014-08-21 10:11:34 +0800336 const struct regulator_ops *ops;
Liam Girdwood571a3542008-04-30 15:42:28 +0100337 int irq;
338 enum regulator_type type;
339 struct module *owner;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100340
Mark Brownbca7bbf2012-05-09 21:38:33 +0100341 unsigned int min_uV;
342 unsigned int uV_step;
Axel Lin33234e72012-11-27 10:24:33 +0800343 unsigned int linear_min_sel;
Laxman Dewangan5a523602013-09-10 15:45:05 +0530344 int fixed_uV;
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530345 unsigned int ramp_delay;
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200346 int min_dropout_uV;
Mark Brownbca7bbf2012-05-09 21:38:33 +0100347
Mark Brown94d33c02013-07-02 22:52:41 +0100348 const struct regulator_linear_range *linear_ranges;
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300349 const unsigned int *linear_range_selectors;
350
Mark Brown94d33c02013-07-02 22:52:41 +0100351 int n_linear_ranges;
352
Axel Lincffc9592012-05-20 10:30:21 +0800353 const unsigned int *volt_table;
Axel Lina32e0c72019-02-28 21:40:13 +0800354 const unsigned int *curr_table;
Axel Lincffc9592012-05-20 10:30:21 +0800355
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300356 unsigned int vsel_range_reg;
357 unsigned int vsel_range_mask;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100358 unsigned int vsel_reg;
359 unsigned int vsel_mask;
Nikita Kiryanovc0ea88b2015-11-25 13:59:04 +0200360 unsigned int csel_reg;
361 unsigned int csel_mask;
Axel Linc8520b42012-12-18 09:30:10 +0800362 unsigned int apply_reg;
363 unsigned int apply_bit;
Mark Browncd6dffb2012-04-15 12:37:47 +0100364 unsigned int enable_reg;
365 unsigned int enable_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100366 unsigned int enable_val;
367 unsigned int disable_val;
Axel Lin51dcdaf2013-03-05 14:16:00 +0800368 bool enable_is_inverted;
Mark Browndf367932012-08-27 16:04:23 -0700369 unsigned int bypass_reg;
370 unsigned int bypass_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100371 unsigned int bypass_val_on;
372 unsigned int bypass_val_off;
Laxman Dewangan354794d2016-03-02 16:24:47 +0530373 unsigned int active_discharge_on;
374 unsigned int active_discharge_off;
375 unsigned int active_discharge_mask;
376 unsigned int active_discharge_reg;
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100377 unsigned int soft_start_reg;
378 unsigned int soft_start_mask;
379 unsigned int soft_start_val_on;
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100380 unsigned int pull_down_reg;
381 unsigned int pull_down_mask;
382 unsigned int pull_down_val_on;
Mark Brown79511ed2012-06-27 14:23:10 +0100383
384 unsigned int enable_time;
Guodong Xu871f5652014-08-13 19:33:40 +0800385
386 unsigned int off_on_delay;
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100387
388 unsigned int (*of_map_mode)(unsigned int mode);
Liam Girdwood571a3542008-04-30 15:42:28 +0100389};
390
Mark Brownc1727082012-04-04 00:50:22 +0100391/**
392 * struct regulator_config - Dynamic regulator descriptor
393 *
394 * Each regulator registered with the core is described with a
395 * structure of this type and a struct regulator_desc. This structure
396 * contains the runtime variable parts of the regulator description.
397 *
398 * @dev: struct device for the regulator
399 * @init_data: platform provided init data, passed through by driver
400 * @driver_data: private regulator data
401 * @of_node: OpenFirmware node to parse for device tree bindings (may be
402 * NULL).
Axel Lincf392842015-03-18 08:57:41 +0800403 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
Mark Brown380a0e62012-08-31 10:31:53 -0700404 * insufficient.
Linus Walleij541d0522019-01-29 11:31:56 +0100405 * @ena_gpiod: GPIO controlling regulator enable.
Mark Brownc1727082012-04-04 00:50:22 +0100406 */
407struct regulator_config {
408 struct device *dev;
409 const struct regulator_init_data *init_data;
410 void *driver_data;
411 struct device_node *of_node;
Mark Brown65b19ce2012-04-15 11:16:05 +0100412 struct regmap *regmap;
Mark Brown65f73502012-06-27 14:14:38 +0100413
Linus Walleije45e2902018-02-12 14:16:57 +0100414 struct gpio_desc *ena_gpiod;
Mark Brownc1727082012-04-04 00:50:22 +0100415};
416
Mark Brown1fa9ad52009-01-21 14:08:40 +0000417/*
Maciej Purskia085a312018-04-23 16:33:39 +0200418 * struct coupling_desc
419 *
420 * Describes coupling of regulators. Each regulator should have
421 * at least a pointer to itself in coupled_rdevs array.
422 * When a new coupled regulator is resolved, n_resolved is
423 * incremented.
424 */
425struct coupling_desc {
426 struct regulator_dev *coupled_rdevs[MAX_COUPLED];
427 int n_resolved;
428 int n_coupled;
429};
430
431/*
Mark Brown1fa9ad52009-01-21 14:08:40 +0000432 * struct regulator_dev
433 *
434 * Voltage / Current regulator class device. One for each
435 * regulator.
436 *
437 * This should *not* be used directly by anything except the regulator
438 * core and notification injection (which should take the mutex and do
439 * no other direct access).
440 */
441struct regulator_dev {
Mark Brown65f26842012-04-03 20:46:53 +0100442 const struct regulator_desc *desc;
Mark Brown5ffbd132009-07-21 16:00:23 +0100443 int exclusive;
Mark Brown1130e5b2010-12-21 23:49:31 +0000444 u32 use_count;
445 u32 open_count;
Mark Brownf59c8f92012-08-31 10:36:37 -0700446 u32 bypass_count;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000447
448 /* lists we belong to */
449 struct list_head list; /* list of all regulators */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000450
451 /* lists we own */
452 struct list_head consumer_list; /* consumers we supply */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000453
Maciej Purskia085a312018-04-23 16:33:39 +0200454 struct coupling_desc coupling_desc;
455
Mark Brown1fa9ad52009-01-21 14:08:40 +0000456 struct blocking_notifier_head notifier;
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300457 struct ww_mutex mutex; /* consumer lock */
Maciej Purski66cf9a72018-04-23 16:33:37 +0200458 struct task_struct *mutex_owner;
459 int ref_cnt;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000460 struct module *owner;
461 struct device dev;
462 struct regulation_constraints *constraints;
Mark Brown3801b862011-06-09 16:22:22 +0100463 struct regulator *supply; /* for tree */
Bjorn Andersson6261b062015-03-24 18:56:05 -0700464 const char *supply_name;
Mark Brown65b19ce2012-04-15 11:16:05 +0100465 struct regmap *regmap;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000466
Mark Brownda07ecd2011-09-11 09:53:50 +0100467 struct delayed_work disable_work;
Mark Brownda07ecd2011-09-11 09:53:50 +0100468
Mark Brown1fa9ad52009-01-21 14:08:40 +0000469 void *reg_data; /* regulator_dev data */
Mark Brown1130e5b2010-12-21 23:49:31 +0000470
Mark Brown1130e5b2010-12-21 23:49:31 +0000471 struct dentry *debugfs;
Mark Brown65f73502012-06-27 14:14:38 +0100472
Kim, Milof19b00d2013-02-18 06:50:39 +0000473 struct regulator_enable_gpio *ena_pin;
Mark Brown65f73502012-06-27 14:14:38 +0100474 unsigned int ena_gpio_state:1;
Guodong Xu871f5652014-08-13 19:33:40 +0800475
Matthias Kaehlckefd086042017-03-27 16:54:12 -0700476 unsigned int is_switch:1;
477
Guodong Xu871f5652014-08-13 19:33:40 +0800478 /* time when this regulator was disabled last time */
479 unsigned long last_off_jiffy;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000480};
481
Mark Brown65f26842012-04-03 20:46:53 +0100482struct regulator_dev *
483regulator_register(const struct regulator_desc *regulator_desc,
Mark Brownc1727082012-04-04 00:50:22 +0100484 const struct regulator_config *config);
Mark Brownb33e46b2013-08-31 11:58:26 +0100485struct regulator_dev *
486devm_regulator_register(struct device *dev,
487 const struct regulator_desc *regulator_desc,
488 const struct regulator_config *config);
Liam Girdwood571a3542008-04-30 15:42:28 +0100489void regulator_unregister(struct regulator_dev *rdev);
Mark Brownb33e46b2013-08-31 11:58:26 +0100490void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100491
492int regulator_notifier_call_chain(struct regulator_dev *rdev,
493 unsigned long event, void *data);
494
495void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100496struct device *rdev_get_dev(struct regulator_dev *rdev);
Bartosz Golaszewski03c87b92019-01-09 18:44:00 +0100497struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100498int rdev_get_id(struct regulator_dev *rdev);
499
Mark Brownbe721972009-08-04 20:09:52 +0200500int regulator_mode_to_status(unsigned int);
501
Mark Brownbca7bbf2012-05-09 21:38:33 +0100502int regulator_list_voltage_linear(struct regulator_dev *rdev,
503 unsigned int selector);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300504int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
505 unsigned int selector);
Mark Brown94d33c02013-07-02 22:52:41 +0100506int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
507 unsigned int selector);
Axel Lincffc9592012-05-20 10:30:21 +0800508int regulator_list_voltage_table(struct regulator_dev *rdev,
509 unsigned int selector);
Mark Brownbca7bbf2012-05-09 21:38:33 +0100510int regulator_map_voltage_linear(struct regulator_dev *rdev,
511 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300512int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
513 int min_uV, int max_uV);
Mark Brown94d33c02013-07-02 22:52:41 +0100514int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
515 int min_uV, int max_uV);
Mark Browne843fc42012-05-09 21:16:06 +0100516int regulator_map_voltage_iterate(struct regulator_dev *rdev,
517 int min_uV, int max_uV);
Axel Linfcf371e2013-04-18 10:34:49 +0800518int regulator_map_voltage_ascend(struct regulator_dev *rdev,
519 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300520int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
521int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
522 unsigned int sel);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100523int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
524int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
Mark Browncd6dffb2012-04-15 12:37:47 +0100525int regulator_is_enabled_regmap(struct regulator_dev *rdev);
526int regulator_enable_regmap(struct regulator_dev *rdev);
527int regulator_disable_regmap(struct regulator_dev *rdev);
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530528int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
529 unsigned int old_selector,
530 unsigned int new_selector);
Mark Browndf367932012-08-27 16:04:23 -0700531int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
532int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100533int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100534int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100535
Laxman Dewangan354794d2016-03-02 16:24:47 +0530536int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
537 bool enable);
Axel Lina32e0c72019-02-28 21:40:13 +0800538int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
539 int min_uA, int max_uA);
540int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100541void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
542
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300543void regulator_lock(struct regulator_dev *rdev);
544void regulator_unlock(struct regulator_dev *rdev);
545
Matti Vaittinen6a47b4d2019-02-14 11:38:05 +0200546/*
547 * Helper functions intended to be used by regulator drivers prior registering
548 * their regulators.
549 */
550int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
551 unsigned int selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100552#endif