blob: a9c030192147dffd23610082ae8a22426dc000c7 [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
Maciej Purskia085a312018-04-23 16:33:39 +020018#define MAX_COUPLED 4
19
Liam Girdwood571a3542008-04-30 15:42:28 +010020#include <linux/device.h>
Paul Gortmakerced55d42011-07-17 16:24:35 -040021#include <linux/notifier.h>
Liam Girdwood571a3542008-04-30 15:42:28 +010022#include <linux/regulator/consumer.h>
23
Linus Walleije45e2902018-02-12 14:16:57 +010024struct gpio_desc;
Mark Brown65b19ce2012-04-15 11:16:05 +010025struct regmap;
Liam Girdwood571a3542008-04-30 15:42:28 +010026struct regulator_dev;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +010027struct regulator_config;
Liam Girdwooda5766f12008-10-10 13:22:20 +010028struct regulator_init_data;
Kim, Milof19b00d2013-02-18 06:50:39 +000029struct regulator_enable_gpio;
Liam Girdwood571a3542008-04-30 15:42:28 +010030
David Brownell853116a2009-01-14 23:03:17 -080031enum regulator_status {
32 REGULATOR_STATUS_OFF,
33 REGULATOR_STATUS_ON,
34 REGULATOR_STATUS_ERROR,
35 /* fast/normal/idle/standby are flavors of "on" */
36 REGULATOR_STATUS_FAST,
37 REGULATOR_STATUS_NORMAL,
38 REGULATOR_STATUS_IDLE,
39 REGULATOR_STATUS_STANDBY,
Mark Brownf59c8f92012-08-31 10:36:37 -070040 /* The regulator is enabled but not regulating */
41 REGULATOR_STATUS_BYPASS,
Krystian Garbaciak1beaf762012-07-12 13:53:35 +010042 /* in case that any other status doesn't apply */
43 REGULATOR_STATUS_UNDEFINED,
David Brownell853116a2009-01-14 23:03:17 -080044};
45
Liam Girdwood571a3542008-04-30 15:42:28 +010046/**
Randy Dunlap7c2330f2013-09-16 18:08:02 -070047 * struct regulator_linear_range - specify linear voltage ranges
48 *
Matthias Kaehlcke7bd0c7b2018-06-07 16:51:38 -070049 * Specify a range of voltages for regulator_map_linear_range() and
Mark Brown94d33c02013-07-02 22:52:41 +010050 * regulator_list_linear_range().
51 *
52 * @min_uV: Lowest voltage in range
Mark Brown94d33c02013-07-02 22:52:41 +010053 * @min_sel: Lowest selector for range
54 * @max_sel: Highest selector for range
55 * @uV_step: Step size
56 */
57struct regulator_linear_range {
58 unsigned int min_uV;
Mark Brown94d33c02013-07-02 22:52:41 +010059 unsigned int min_sel;
60 unsigned int max_sel;
61 unsigned int uV_step;
62};
63
Axel Lin8828bae2013-10-11 09:32:18 +080064/* Initialize struct regulator_linear_range */
65#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
66{ \
67 .min_uV = _min_uV, \
68 .min_sel = _min_sel, \
69 .max_sel = _max_sel, \
70 .uV_step = _step_uV, \
71}
72
Mark Brown94d33c02013-07-02 22:52:41 +010073/**
Liam Girdwood571a3542008-04-30 15:42:28 +010074 * struct regulator_ops - regulator operations.
75 *
David Brownell3b2a6062009-02-26 13:28:41 -080076 * @enable: Configure the regulator as enabled.
77 * @disable: Configure the regulator as disabled.
Wolfram Sangd87b9692009-09-18 22:44:46 +020078 * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
79 * May also return negative errno.
Mark Brownc8e7e462008-12-31 12:52:42 +000080 *
81 * @set_voltage: Set the voltage for the regulator within the range specified.
82 * The driver should select the voltage closest to min_uV.
Mark Browne8eef822010-12-12 14:36:17 +000083 * @set_voltage_sel: Set the voltage for the regulator using the specified
84 * selector.
Mark Browne843fc42012-05-09 21:16:06 +010085 * @map_voltage: Convert a voltage into a selector
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070086 * @get_voltage: Return the currently configured voltage for the regulator;
87 * return -ENOTRECOVERABLE if regulator can't be read at
88 * bootup and hasn't been set yet.
Mark Brown476c2d82010-12-10 17:28:07 +000089 * @get_voltage_sel: Return the currently configured voltage selector for the
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070090 * regulator; return -ENOTRECOVERABLE if regulator can't
91 * be read at bootup and hasn't been set yet.
David Brownell4367cfd2009-02-26 11:48:36 -080092 * @list_voltage: Return one of the supported voltages, in microvolts; zero
93 * if the selector indicates a voltage that is unusable on this system;
94 * or negative errno. Selectors range from zero to one less than
95 * regulator_desc.n_voltages. Voltages may be reported in any order.
Mark Brownc8e7e462008-12-31 12:52:42 +000096 *
Mark Brownc8e7e462008-12-31 12:52:42 +000097 * @set_current_limit: Configure a limit for a current-limited regulator.
Axel Lin89009e12012-08-08 20:17:18 +080098 * The driver should select the current closest to max_uA.
David Brownell3b2a6062009-02-26 13:28:41 -080099 * @get_current_limit: Get the configured limit for a current-limited regulator.
Stephen Boyd36e4f832015-06-11 17:37:06 -0700100 * @set_input_current_limit: Configure an input limit.
Mark Brownc8e7e462008-12-31 12:52:42 +0000101 *
Luis de Bethencourtabf2f822016-03-23 11:35:39 +0000102 * @set_over_current_protection: Support capability of automatically shutting
103 * down when detecting an over current event.
104 *
Laxman Dewangan670666b2016-03-02 16:24:46 +0530105 * @set_active_discharge: Set active discharge enable/disable of regulators.
106 *
Randy Dunlap9f6532512009-04-03 21:31:30 -0700107 * @set_mode: Set the configured operating mode for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800108 * @get_mode: Get the configured operating mode for the regulator.
Axel Haslam1b5b4222016-11-03 12:11:42 +0100109 * @get_error_flags: Get the current error(s) for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800110 * @get_status: Return actual (not as-configured) status of regulator, as a
111 * REGULATOR_STATUS value (or negative errno)
Mark Brownc8e7e462008-12-31 12:52:42 +0000112 * @get_optimum_mode: Get the most efficient operating mode for the regulator
113 * when running with the specified parameters.
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800114 * @set_load: Set the load for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000115 *
Mark Brownf59c8f92012-08-31 10:36:37 -0700116 * @set_bypass: Set the regulator in bypass mode.
117 * @get_bypass: Get the regulator bypass mode state.
118 *
Mark Brown31aae2b2009-12-21 12:21:52 +0000119 * @enable_time: Time taken for the regulator voltage output voltage to
Linus Walleij77af1b22011-03-17 13:24:36 +0100120 * stabilise after being enabled, in microseconds.
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530121 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
122 * select ramp delay equal to or less than(closest) ramp_delay.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700123 * @set_voltage_time: Time taken for the regulator voltage output voltage
124 * to stabilise after being set to a new value, in microseconds.
125 * The function receives the from and to voltage as input, it
126 * should return the worst case.
Linus Walleij77af1b22011-03-17 13:24:36 +0100127 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
128 * to stabilise after being set to a new value, in microseconds.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700129 * The function receives the from and to voltage selector as
130 * input, it should return the worst case.
Stephen Boydc751ad02015-06-12 15:48:06 -0700131 * @set_soft_start: Enable soft start for the regulator.
Mark Brown31aae2b2009-12-21 12:21:52 +0000132 *
Mark Brownc8e7e462008-12-31 12:52:42 +0000133 * @set_suspend_voltage: Set the voltage for the regulator when the system
134 * is suspended.
135 * @set_suspend_enable: Mark the regulator as enabled when the system is
136 * suspended.
137 * @set_suspend_disable: Mark the regulator as disabled when the system is
138 * suspended.
139 * @set_suspend_mode: Set the operating mode for the regulator when the
140 * system is suspended.
David Brownell3b2a6062009-02-26 13:28:41 -0800141 *
Stephen Boyd23c779b2015-06-11 17:37:04 -0700142 * @set_pull_down: Configure the regulator to pull down when the regulator
143 * is disabled.
144 *
David Brownell3b2a6062009-02-26 13:28:41 -0800145 * This struct describes regulator operations which can be implemented by
146 * regulator chip drivers.
Liam Girdwood571a3542008-04-30 15:42:28 +0100147 */
148struct regulator_ops {
149
David Brownell4367cfd2009-02-26 11:48:36 -0800150 /* enumerate supported voltages */
151 int (*list_voltage) (struct regulator_dev *, unsigned selector);
152
Liam Girdwood571a3542008-04-30 15:42:28 +0100153 /* get/set regulator voltage */
Mark Brown3a93f2a2010-11-10 14:38:29 +0000154 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
155 unsigned *selector);
Mark Browne843fc42012-05-09 21:16:06 +0100156 int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
Mark Browne8eef822010-12-12 14:36:17 +0000157 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100158 int (*get_voltage) (struct regulator_dev *);
Mark Brown476c2d82010-12-10 17:28:07 +0000159 int (*get_voltage_sel) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100160
161 /* get/set regulator current */
162 int (*set_current_limit) (struct regulator_dev *,
163 int min_uA, int max_uA);
164 int (*get_current_limit) (struct regulator_dev *);
165
Stephen Boyd36e4f832015-06-11 17:37:06 -0700166 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
Stephen Boyd3a003ba2015-07-17 14:41:54 -0700167 int (*set_over_current_protection) (struct regulator_dev *);
Laxman Dewangan670666b2016-03-02 16:24:46 +0530168 int (*set_active_discharge) (struct regulator_dev *, bool enable);
Stephen Boyd36e4f832015-06-11 17:37:06 -0700169
Liam Girdwood571a3542008-04-30 15:42:28 +0100170 /* enable/disable regulator */
171 int (*enable) (struct regulator_dev *);
172 int (*disable) (struct regulator_dev *);
173 int (*is_enabled) (struct regulator_dev *);
174
Kim, Milofde297bb2012-02-16 22:41:32 -0800175 /* get/set regulator operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100176 int (*set_mode) (struct regulator_dev *, unsigned int mode);
177 unsigned int (*get_mode) (struct regulator_dev *);
178
Axel Haslam1b5b4222016-11-03 12:11:42 +0100179 /* retrieve current error flags on the regulator */
180 int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
181
Linus Walleij77af1b22011-03-17 13:24:36 +0100182 /* Time taken to enable or set voltage on the regulator */
Mark Brown31aae2b2009-12-21 12:21:52 +0000183 int (*enable_time) (struct regulator_dev *);
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530184 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700185 int (*set_voltage_time) (struct regulator_dev *, int old_uV,
186 int new_uV);
Linus Walleij77af1b22011-03-17 13:24:36 +0100187 int (*set_voltage_time_sel) (struct regulator_dev *,
188 unsigned int old_selector,
189 unsigned int new_selector);
Mark Brown31aae2b2009-12-21 12:21:52 +0000190
Stephen Boyd57f66b72015-06-11 17:37:05 -0700191 int (*set_soft_start) (struct regulator_dev *);
192
David Brownell853116a2009-01-14 23:03:17 -0800193 /* report regulator status ... most other accessors report
194 * control inputs, this reports results of combining inputs
195 * from Linux (and other sources) with the actual load.
David Brownell3b2a6062009-02-26 13:28:41 -0800196 * returns REGULATOR_STATUS_* or negative errno.
David Brownell853116a2009-01-14 23:03:17 -0800197 */
198 int (*get_status)(struct regulator_dev *);
199
Liam Girdwood571a3542008-04-30 15:42:28 +0100200 /* get most efficient regulator operating mode for load */
201 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
202 int output_uV, int load_uA);
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800203 /* set the load on the regulator */
204 int (*set_load)(struct regulator_dev *, int load_uA);
Liam Girdwood571a3542008-04-30 15:42:28 +0100205
Mark Brownf59c8f92012-08-31 10:36:37 -0700206 /* control and report on bypass mode */
207 int (*set_bypass)(struct regulator_dev *dev, bool enable);
208 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
209
Liam Girdwood571a3542008-04-30 15:42:28 +0100210 /* the operations below are for configuration of regulator state when
Mark Brown3de89602008-09-09 16:21:17 +0100211 * its parent PMIC enters a global STANDBY/HIBERNATE state */
Liam Girdwood571a3542008-04-30 15:42:28 +0100212
213 /* set regulator suspend voltage */
214 int (*set_suspend_voltage) (struct regulator_dev *, int uV);
215
216 /* enable/disable regulator in suspend state */
217 int (*set_suspend_enable) (struct regulator_dev *);
218 int (*set_suspend_disable) (struct regulator_dev *);
219
Kim, Milofde297bb2012-02-16 22:41:32 -0800220 /* set regulator suspend operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100221 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
Stephen Boyd23c779b2015-06-11 17:37:04 -0700222
pascal paillet0380cf72018-07-05 14:25:57 +0000223 int (*resume)(struct regulator_dev *rdev);
Chunyan Zhangf7efad12018-01-26 21:08:47 +0800224
Stephen Boyd23c779b2015-06-11 17:37:04 -0700225 int (*set_pull_down) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100226};
227
228/*
229 * Regulators can either control voltage or current.
230 */
231enum regulator_type {
232 REGULATOR_VOLTAGE,
233 REGULATOR_CURRENT,
234};
235
236/**
Mark Brownc1727082012-04-04 00:50:22 +0100237 * struct regulator_desc - Static regulator descriptor
Liam Girdwood571a3542008-04-30 15:42:28 +0100238 *
Mark Brownc1727082012-04-04 00:50:22 +0100239 * Each regulator registered with the core is described with a
240 * structure of this type and a struct regulator_config. This
241 * structure contains the non-varying parts of the regulator
242 * description.
Mark Brownc8e7e462008-12-31 12:52:42 +0000243 *
244 * @name: Identifying name for the regulator.
Rajendra Nayak69511a42011-11-18 16:47:20 +0530245 * @supply_name: Identifying the regulator supply
Mark Browna0c7b162014-09-09 23:13:57 +0100246 * @of_match: Name used to identify regulator in DT.
247 * @regulators_node: Name of node containing regulator definitions in DT.
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100248 * @of_parse_cb: Optional callback called only if of_match is present.
249 * Will be called for each regulator parsed from DT, during
250 * init_data parsing.
251 * The regulator_config passed as argument to the callback will
252 * be a copy of config passed to regulator_register, valid only
253 * for this particular call. Callback may freely change the
254 * config but it cannot store it for later usage.
255 * Callback should return 0 on success or negative ERRNO
256 * indicating failure.
Mark Brownc8e7e462008-12-31 12:52:42 +0000257 * @id: Numerical identifier for the regulator.
258 * @ops: Regulator operations table.
Randy Dunlap0ba48872009-01-08 11:50:23 -0800259 * @irq: Interrupt number for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000260 * @type: Indicates if the regulator is a voltage or current regulator.
261 * @owner: Module providing the regulator, used for refcounting.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100262 *
Pawel Mollbd7a2b62012-09-24 18:56:53 +0100263 * @continuous_voltage_range: Indicates if the regulator can set any
264 * voltage within constrains range.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100265 * @n_voltages: Number of selectors available for ops.list_voltage().
266 *
267 * @min_uV: Voltage given by the lowest selector (if linear mapping)
268 * @uV_step: Voltage increase with each selector (if linear mapping)
Axel Lin33234e72012-11-27 10:24:33 +0800269 * @linear_min_sel: Minimal selector for starting linear mapping
Laxman Dewangan5a523602013-09-10 15:45:05 +0530270 * @fixed_uV: Fixed voltage of rails.
Axel Linea38d132012-06-18 14:03:16 +0800271 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200272 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700273 * @linear_ranges: A constant table of possible voltage ranges.
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300274 * @linear_range_selectors: A constant table of voltage range selectors.
275 * If pickable ranges are used each range must
276 * have corresponding selector here.
277 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
278 * linear_range_selectors if used) table(s).
Axel Lincffc9592012-05-20 10:30:21 +0800279 * @volt_table: Voltage 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
Luis de Bethencourtd13d3a52016-03-23 11:24:47 +0000286 * @csel_reg: Register for TPS65218 LS3 current regulator
287 * @csel_mask: Mask for TPS65218 LS3 current regulator
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 Lindf11e502014-08-21 10:11:34 +0800335 const struct regulator_ops *ops;
Liam Girdwood571a3542008-04-30 15:42:28 +0100336 int irq;
337 enum regulator_type type;
338 struct module *owner;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100339
Mark Brownbca7bbf2012-05-09 21:38:33 +0100340 unsigned int min_uV;
341 unsigned int uV_step;
Axel Lin33234e72012-11-27 10:24:33 +0800342 unsigned int linear_min_sel;
Laxman Dewangan5a523602013-09-10 15:45:05 +0530343 int fixed_uV;
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530344 unsigned int ramp_delay;
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200345 int min_dropout_uV;
Mark Brownbca7bbf2012-05-09 21:38:33 +0100346
Mark Brown94d33c02013-07-02 22:52:41 +0100347 const struct regulator_linear_range *linear_ranges;
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300348 const unsigned int *linear_range_selectors;
349
Mark Brown94d33c02013-07-02 22:52:41 +0100350 int n_linear_ranges;
351
Axel Lincffc9592012-05-20 10:30:21 +0800352 const unsigned int *volt_table;
353
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300354 unsigned int vsel_range_reg;
355 unsigned int vsel_range_mask;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100356 unsigned int vsel_reg;
357 unsigned int vsel_mask;
Nikita Kiryanovc0ea88b2015-11-25 13:59:04 +0200358 unsigned int csel_reg;
359 unsigned int csel_mask;
Axel Linc8520b42012-12-18 09:30:10 +0800360 unsigned int apply_reg;
361 unsigned int apply_bit;
Mark Browncd6dffb2012-04-15 12:37:47 +0100362 unsigned int enable_reg;
363 unsigned int enable_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100364 unsigned int enable_val;
365 unsigned int disable_val;
Axel Lin51dcdaf2013-03-05 14:16:00 +0800366 bool enable_is_inverted;
Mark Browndf367932012-08-27 16:04:23 -0700367 unsigned int bypass_reg;
368 unsigned int bypass_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100369 unsigned int bypass_val_on;
370 unsigned int bypass_val_off;
Laxman Dewangan354794d2016-03-02 16:24:47 +0530371 unsigned int active_discharge_on;
372 unsigned int active_discharge_off;
373 unsigned int active_discharge_mask;
374 unsigned int active_discharge_reg;
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100375 unsigned int soft_start_reg;
376 unsigned int soft_start_mask;
377 unsigned int soft_start_val_on;
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100378 unsigned int pull_down_reg;
379 unsigned int pull_down_mask;
380 unsigned int pull_down_val_on;
Mark Brown79511ed2012-06-27 14:23:10 +0100381
382 unsigned int enable_time;
Guodong Xu871f5652014-08-13 19:33:40 +0800383
384 unsigned int off_on_delay;
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100385
386 unsigned int (*of_map_mode)(unsigned int mode);
Liam Girdwood571a3542008-04-30 15:42:28 +0100387};
388
Mark Brownc1727082012-04-04 00:50:22 +0100389/**
390 * struct regulator_config - Dynamic regulator descriptor
391 *
392 * Each regulator registered with the core is described with a
393 * structure of this type and a struct regulator_desc. This structure
394 * contains the runtime variable parts of the regulator description.
395 *
396 * @dev: struct device for the regulator
397 * @init_data: platform provided init data, passed through by driver
398 * @driver_data: private regulator data
399 * @of_node: OpenFirmware node to parse for device tree bindings (may be
400 * NULL).
Axel Lincf392842015-03-18 08:57:41 +0800401 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
Mark Brown380a0e62012-08-31 10:31:53 -0700402 * insufficient.
Markus Pargmann76f439d2014-10-08 15:47:05 +0200403 * @ena_gpio_initialized: GPIO controlling regulator enable was properly
404 * initialized, meaning that >= 0 is a valid gpio
405 * identifier and < 0 is a non existent gpio.
Mark Brown65f73502012-06-27 14:14:38 +0100406 * @ena_gpio: GPIO controlling regulator enable.
Linus Walleije45e2902018-02-12 14:16:57 +0100407 * @ena_gpiod: GPIO descriptor controlling regulator enable.
Mark Brown65f73502012-06-27 14:14:38 +0100408 * @ena_gpio_invert: Sense for GPIO enable control.
409 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
Mark Brownc1727082012-04-04 00:50:22 +0100410 */
411struct regulator_config {
412 struct device *dev;
413 const struct regulator_init_data *init_data;
414 void *driver_data;
415 struct device_node *of_node;
Mark Brown65b19ce2012-04-15 11:16:05 +0100416 struct regmap *regmap;
Mark Brown65f73502012-06-27 14:14:38 +0100417
Markus Pargmann76f439d2014-10-08 15:47:05 +0200418 bool ena_gpio_initialized;
Mark Brown65f73502012-06-27 14:14:38 +0100419 int ena_gpio;
Linus Walleije45e2902018-02-12 14:16:57 +0100420 struct gpio_desc *ena_gpiod;
Mark Brown65f73502012-06-27 14:14:38 +0100421 unsigned int ena_gpio_invert:1;
422 unsigned int ena_gpio_flags;
Mark Brownc1727082012-04-04 00:50:22 +0100423};
424
Mark Brown1fa9ad52009-01-21 14:08:40 +0000425/*
Maciej Purskia085a312018-04-23 16:33:39 +0200426 * struct coupling_desc
427 *
428 * Describes coupling of regulators. Each regulator should have
429 * at least a pointer to itself in coupled_rdevs array.
430 * When a new coupled regulator is resolved, n_resolved is
431 * incremented.
432 */
433struct coupling_desc {
434 struct regulator_dev *coupled_rdevs[MAX_COUPLED];
435 int n_resolved;
436 int n_coupled;
437};
438
439/*
Mark Brown1fa9ad52009-01-21 14:08:40 +0000440 * struct regulator_dev
441 *
442 * Voltage / Current regulator class device. One for each
443 * regulator.
444 *
445 * This should *not* be used directly by anything except the regulator
446 * core and notification injection (which should take the mutex and do
447 * no other direct access).
448 */
449struct regulator_dev {
Mark Brown65f26842012-04-03 20:46:53 +0100450 const struct regulator_desc *desc;
Mark Brown5ffbd132009-07-21 16:00:23 +0100451 int exclusive;
Mark Brown1130e5b2010-12-21 23:49:31 +0000452 u32 use_count;
453 u32 open_count;
Mark Brownf59c8f92012-08-31 10:36:37 -0700454 u32 bypass_count;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000455
456 /* lists we belong to */
457 struct list_head list; /* list of all regulators */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000458
459 /* lists we own */
460 struct list_head consumer_list; /* consumers we supply */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000461
Maciej Purskia085a312018-04-23 16:33:39 +0200462 struct coupling_desc coupling_desc;
463
Mark Brown1fa9ad52009-01-21 14:08:40 +0000464 struct blocking_notifier_head notifier;
465 struct mutex mutex; /* consumer lock */
Maciej Purski66cf9a72018-04-23 16:33:37 +0200466 struct task_struct *mutex_owner;
467 int ref_cnt;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000468 struct module *owner;
469 struct device dev;
470 struct regulation_constraints *constraints;
Mark Brown3801b862011-06-09 16:22:22 +0100471 struct regulator *supply; /* for tree */
Bjorn Andersson6261b062015-03-24 18:56:05 -0700472 const char *supply_name;
Mark Brown65b19ce2012-04-15 11:16:05 +0100473 struct regmap *regmap;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000474
Mark Brownda07ecd2011-09-11 09:53:50 +0100475 struct delayed_work disable_work;
476 int deferred_disables;
477
Mark Brown1fa9ad52009-01-21 14:08:40 +0000478 void *reg_data; /* regulator_dev data */
Mark Brown1130e5b2010-12-21 23:49:31 +0000479
Mark Brown1130e5b2010-12-21 23:49:31 +0000480 struct dentry *debugfs;
Mark Brown65f73502012-06-27 14:14:38 +0100481
Kim, Milof19b00d2013-02-18 06:50:39 +0000482 struct regulator_enable_gpio *ena_pin;
Mark Brown65f73502012-06-27 14:14:38 +0100483 unsigned int ena_gpio_state:1;
Guodong Xu871f5652014-08-13 19:33:40 +0800484
Matthias Kaehlckefd086042017-03-27 16:54:12 -0700485 unsigned int is_switch:1;
486
Guodong Xu871f5652014-08-13 19:33:40 +0800487 /* time when this regulator was disabled last time */
488 unsigned long last_off_jiffy;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000489};
490
Mark Brown65f26842012-04-03 20:46:53 +0100491struct regulator_dev *
492regulator_register(const struct regulator_desc *regulator_desc,
Mark Brownc1727082012-04-04 00:50:22 +0100493 const struct regulator_config *config);
Mark Brownb33e46b2013-08-31 11:58:26 +0100494struct regulator_dev *
495devm_regulator_register(struct device *dev,
496 const struct regulator_desc *regulator_desc,
497 const struct regulator_config *config);
Liam Girdwood571a3542008-04-30 15:42:28 +0100498void regulator_unregister(struct regulator_dev *rdev);
Mark Brownb33e46b2013-08-31 11:58:26 +0100499void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100500
501int regulator_notifier_call_chain(struct regulator_dev *rdev,
502 unsigned long event, void *data);
503
504void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100505struct device *rdev_get_dev(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100506int rdev_get_id(struct regulator_dev *rdev);
507
Mark Brownbe721972009-08-04 20:09:52 +0200508int regulator_mode_to_status(unsigned int);
509
Mark Brownbca7bbf2012-05-09 21:38:33 +0100510int regulator_list_voltage_linear(struct regulator_dev *rdev,
511 unsigned int selector);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300512int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
513 unsigned int selector);
Mark Brown94d33c02013-07-02 22:52:41 +0100514int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
515 unsigned int selector);
Axel Lincffc9592012-05-20 10:30:21 +0800516int regulator_list_voltage_table(struct regulator_dev *rdev,
517 unsigned int selector);
Mark Brownbca7bbf2012-05-09 21:38:33 +0100518int regulator_map_voltage_linear(struct regulator_dev *rdev,
519 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300520int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
521 int min_uV, int max_uV);
Mark Brown94d33c02013-07-02 22:52:41 +0100522int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
523 int min_uV, int max_uV);
Mark Browne843fc42012-05-09 21:16:06 +0100524int regulator_map_voltage_iterate(struct regulator_dev *rdev,
525 int min_uV, int max_uV);
Axel Linfcf371e2013-04-18 10:34:49 +0800526int regulator_map_voltage_ascend(struct regulator_dev *rdev,
527 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300528int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
529int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
530 unsigned int sel);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100531int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
532int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
Mark Browncd6dffb2012-04-15 12:37:47 +0100533int regulator_is_enabled_regmap(struct regulator_dev *rdev);
534int regulator_enable_regmap(struct regulator_dev *rdev);
535int regulator_disable_regmap(struct regulator_dev *rdev);
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530536int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
537 unsigned int old_selector,
538 unsigned int new_selector);
Mark Browndf367932012-08-27 16:04:23 -0700539int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
540int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100541int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100542int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100543
Laxman Dewangan354794d2016-03-02 16:24:47 +0530544int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
545 bool enable);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100546void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
547
Liam Girdwood571a3542008-04-30 15:42:28 +0100548#endif