blob: 377da235711895321220522f3d3595817c1485a9 [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
Dmitry Osipenko40c223e2018-10-05 18:36:33 +030018#define MAX_COUPLED 2
Maciej Purskia085a312018-04-23 16:33:39 +020019
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>
Dmitry Osipenkof8702f92018-11-19 00:56:17 +030023#include <linux/ww_mutex.h>
Liam Girdwood571a3542008-04-30 15:42:28 +010024
Linus Walleije45e2902018-02-12 14:16:57 +010025struct gpio_desc;
Mark Brown65b19ce2012-04-15 11:16:05 +010026struct regmap;
Liam Girdwood571a3542008-04-30 15:42:28 +010027struct regulator_dev;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +010028struct regulator_config;
Liam Girdwooda5766f12008-10-10 13:22:20 +010029struct regulator_init_data;
Kim, Milof19b00d2013-02-18 06:50:39 +000030struct regulator_enable_gpio;
Liam Girdwood571a3542008-04-30 15:42:28 +010031
David Brownell853116a2009-01-14 23:03:17 -080032enum regulator_status {
33 REGULATOR_STATUS_OFF,
34 REGULATOR_STATUS_ON,
35 REGULATOR_STATUS_ERROR,
36 /* fast/normal/idle/standby are flavors of "on" */
37 REGULATOR_STATUS_FAST,
38 REGULATOR_STATUS_NORMAL,
39 REGULATOR_STATUS_IDLE,
40 REGULATOR_STATUS_STANDBY,
Mark Brownf59c8f92012-08-31 10:36:37 -070041 /* The regulator is enabled but not regulating */
42 REGULATOR_STATUS_BYPASS,
Krystian Garbaciak1beaf762012-07-12 13:53:35 +010043 /* in case that any other status doesn't apply */
44 REGULATOR_STATUS_UNDEFINED,
David Brownell853116a2009-01-14 23:03:17 -080045};
46
Liam Girdwood571a3542008-04-30 15:42:28 +010047/**
Randy Dunlap7c2330f2013-09-16 18:08:02 -070048 * struct regulator_linear_range - specify linear voltage ranges
49 *
Matthias Kaehlcke7bd0c7b2018-06-07 16:51:38 -070050 * Specify a range of voltages for regulator_map_linear_range() and
Mark Brown94d33c02013-07-02 22:52:41 +010051 * regulator_list_linear_range().
52 *
53 * @min_uV: Lowest voltage in range
Mark Brown94d33c02013-07-02 22:52:41 +010054 * @min_sel: Lowest selector for range
55 * @max_sel: Highest selector for range
56 * @uV_step: Step size
57 */
58struct regulator_linear_range {
59 unsigned int min_uV;
Mark Brown94d33c02013-07-02 22:52:41 +010060 unsigned int min_sel;
61 unsigned int max_sel;
62 unsigned int uV_step;
63};
64
Axel Lin8828bae2013-10-11 09:32:18 +080065/* Initialize struct regulator_linear_range */
66#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
67{ \
68 .min_uV = _min_uV, \
69 .min_sel = _min_sel, \
70 .max_sel = _max_sel, \
71 .uV_step = _step_uV, \
72}
73
Mark Brown94d33c02013-07-02 22:52:41 +010074/**
Liam Girdwood571a3542008-04-30 15:42:28 +010075 * struct regulator_ops - regulator operations.
76 *
David Brownell3b2a6062009-02-26 13:28:41 -080077 * @enable: Configure the regulator as enabled.
78 * @disable: Configure the regulator as disabled.
Wolfram Sangd87b9692009-09-18 22:44:46 +020079 * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
80 * May also return negative errno.
Mark Brownc8e7e462008-12-31 12:52:42 +000081 *
82 * @set_voltage: Set the voltage for the regulator within the range specified.
83 * The driver should select the voltage closest to min_uV.
Mark Browne8eef822010-12-12 14:36:17 +000084 * @set_voltage_sel: Set the voltage for the regulator using the specified
85 * selector.
Mark Browne843fc42012-05-09 21:16:06 +010086 * @map_voltage: Convert a voltage into a selector
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070087 * @get_voltage: Return the currently configured voltage for the regulator;
88 * return -ENOTRECOVERABLE if regulator can't be read at
89 * bootup and hasn't been set yet.
Mark Brown476c2d82010-12-10 17:28:07 +000090 * @get_voltage_sel: Return the currently configured voltage selector for the
Douglas Anderson84b3a7c2018-05-15 15:07:17 -070091 * regulator; return -ENOTRECOVERABLE if regulator can't
92 * be read at bootup and hasn't been set yet.
David Brownell4367cfd2009-02-26 11:48:36 -080093 * @list_voltage: Return one of the supported voltages, in microvolts; zero
94 * if the selector indicates a voltage that is unusable on this system;
95 * or negative errno. Selectors range from zero to one less than
96 * regulator_desc.n_voltages. Voltages may be reported in any order.
Mark Brownc8e7e462008-12-31 12:52:42 +000097 *
Mark Brownc8e7e462008-12-31 12:52:42 +000098 * @set_current_limit: Configure a limit for a current-limited regulator.
Axel Lin89009e12012-08-08 20:17:18 +080099 * The driver should select the current closest to max_uA.
David Brownell3b2a6062009-02-26 13:28:41 -0800100 * @get_current_limit: Get the configured limit for a current-limited regulator.
Stephen Boyd36e4f832015-06-11 17:37:06 -0700101 * @set_input_current_limit: Configure an input limit.
Mark Brownc8e7e462008-12-31 12:52:42 +0000102 *
Luis de Bethencourtabf2f822016-03-23 11:35:39 +0000103 * @set_over_current_protection: Support capability of automatically shutting
104 * down when detecting an over current event.
105 *
Laxman Dewangan670666b2016-03-02 16:24:46 +0530106 * @set_active_discharge: Set active discharge enable/disable of regulators.
107 *
Randy Dunlap9f6532512009-04-03 21:31:30 -0700108 * @set_mode: Set the configured operating mode for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800109 * @get_mode: Get the configured operating mode for the regulator.
Axel Haslam1b5b4222016-11-03 12:11:42 +0100110 * @get_error_flags: Get the current error(s) for the regulator.
David Brownell3b2a6062009-02-26 13:28:41 -0800111 * @get_status: Return actual (not as-configured) status of regulator, as a
112 * REGULATOR_STATUS value (or negative errno)
Mark Brownc8e7e462008-12-31 12:52:42 +0000113 * @get_optimum_mode: Get the most efficient operating mode for the regulator
114 * when running with the specified parameters.
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800115 * @set_load: Set the load for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000116 *
Mark Brownf59c8f92012-08-31 10:36:37 -0700117 * @set_bypass: Set the regulator in bypass mode.
118 * @get_bypass: Get the regulator bypass mode state.
119 *
Mark Brown31aae2b2009-12-21 12:21:52 +0000120 * @enable_time: Time taken for the regulator voltage output voltage to
Linus Walleij77af1b22011-03-17 13:24:36 +0100121 * stabilise after being enabled, in microseconds.
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530122 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
123 * select ramp delay equal to or less than(closest) ramp_delay.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700124 * @set_voltage_time: Time taken for the regulator voltage output voltage
125 * to stabilise after being set to a new value, in microseconds.
126 * The function receives the from and to voltage as input, it
127 * should return the worst case.
Linus Walleij77af1b22011-03-17 13:24:36 +0100128 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
129 * to stabilise after being set to a new value, in microseconds.
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700130 * The function receives the from and to voltage selector as
131 * input, it should return the worst case.
Stephen Boydc751ad02015-06-12 15:48:06 -0700132 * @set_soft_start: Enable soft start for the regulator.
Mark Brown31aae2b2009-12-21 12:21:52 +0000133 *
Mark Brownc8e7e462008-12-31 12:52:42 +0000134 * @set_suspend_voltage: Set the voltage for the regulator when the system
135 * is suspended.
136 * @set_suspend_enable: Mark the regulator as enabled when the system is
137 * suspended.
138 * @set_suspend_disable: Mark the regulator as disabled when the system is
139 * suspended.
140 * @set_suspend_mode: Set the operating mode for the regulator when the
141 * system is suspended.
David Brownell3b2a6062009-02-26 13:28:41 -0800142 *
Stephen Boyd23c779b2015-06-11 17:37:04 -0700143 * @set_pull_down: Configure the regulator to pull down when the regulator
144 * is disabled.
145 *
David Brownell3b2a6062009-02-26 13:28:41 -0800146 * This struct describes regulator operations which can be implemented by
147 * regulator chip drivers.
Liam Girdwood571a3542008-04-30 15:42:28 +0100148 */
149struct regulator_ops {
150
David Brownell4367cfd2009-02-26 11:48:36 -0800151 /* enumerate supported voltages */
152 int (*list_voltage) (struct regulator_dev *, unsigned selector);
153
Liam Girdwood571a3542008-04-30 15:42:28 +0100154 /* get/set regulator voltage */
Mark Brown3a93f2a2010-11-10 14:38:29 +0000155 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
156 unsigned *selector);
Mark Browne843fc42012-05-09 21:16:06 +0100157 int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
Mark Browne8eef822010-12-12 14:36:17 +0000158 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100159 int (*get_voltage) (struct regulator_dev *);
Mark Brown476c2d82010-12-10 17:28:07 +0000160 int (*get_voltage_sel) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100161
162 /* get/set regulator current */
163 int (*set_current_limit) (struct regulator_dev *,
164 int min_uA, int max_uA);
165 int (*get_current_limit) (struct regulator_dev *);
166
Stephen Boyd36e4f832015-06-11 17:37:06 -0700167 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
Stephen Boyd3a003ba2015-07-17 14:41:54 -0700168 int (*set_over_current_protection) (struct regulator_dev *);
Laxman Dewangan670666b2016-03-02 16:24:46 +0530169 int (*set_active_discharge) (struct regulator_dev *, bool enable);
Stephen Boyd36e4f832015-06-11 17:37:06 -0700170
Liam Girdwood571a3542008-04-30 15:42:28 +0100171 /* enable/disable regulator */
172 int (*enable) (struct regulator_dev *);
173 int (*disable) (struct regulator_dev *);
174 int (*is_enabled) (struct regulator_dev *);
175
Kim, Milofde297bb2012-02-16 22:41:32 -0800176 /* get/set regulator operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100177 int (*set_mode) (struct regulator_dev *, unsigned int mode);
178 unsigned int (*get_mode) (struct regulator_dev *);
179
Axel Haslam1b5b4222016-11-03 12:11:42 +0100180 /* retrieve current error flags on the regulator */
181 int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
182
Linus Walleij77af1b22011-03-17 13:24:36 +0100183 /* Time taken to enable or set voltage on the regulator */
Mark Brown31aae2b2009-12-21 12:21:52 +0000184 int (*enable_time) (struct regulator_dev *);
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530185 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
Matthias Kaehlcke73e705b2016-09-14 09:52:08 -0700186 int (*set_voltage_time) (struct regulator_dev *, int old_uV,
187 int new_uV);
Linus Walleij77af1b22011-03-17 13:24:36 +0100188 int (*set_voltage_time_sel) (struct regulator_dev *,
189 unsigned int old_selector,
190 unsigned int new_selector);
Mark Brown31aae2b2009-12-21 12:21:52 +0000191
Stephen Boyd57f66b72015-06-11 17:37:05 -0700192 int (*set_soft_start) (struct regulator_dev *);
193
David Brownell853116a2009-01-14 23:03:17 -0800194 /* report regulator status ... most other accessors report
195 * control inputs, this reports results of combining inputs
196 * from Linux (and other sources) with the actual load.
David Brownell3b2a6062009-02-26 13:28:41 -0800197 * returns REGULATOR_STATUS_* or negative errno.
David Brownell853116a2009-01-14 23:03:17 -0800198 */
199 int (*get_status)(struct regulator_dev *);
200
Liam Girdwood571a3542008-04-30 15:42:28 +0100201 /* get most efficient regulator operating mode for load */
202 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
203 int output_uV, int load_uA);
Bjorn Andersson8f4490e2015-02-11 19:39:12 -0800204 /* set the load on the regulator */
205 int (*set_load)(struct regulator_dev *, int load_uA);
Liam Girdwood571a3542008-04-30 15:42:28 +0100206
Mark Brownf59c8f92012-08-31 10:36:37 -0700207 /* control and report on bypass mode */
208 int (*set_bypass)(struct regulator_dev *dev, bool enable);
209 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
210
Liam Girdwood571a3542008-04-30 15:42:28 +0100211 /* the operations below are for configuration of regulator state when
Mark Brown3de89602008-09-09 16:21:17 +0100212 * its parent PMIC enters a global STANDBY/HIBERNATE state */
Liam Girdwood571a3542008-04-30 15:42:28 +0100213
214 /* set regulator suspend voltage */
215 int (*set_suspend_voltage) (struct regulator_dev *, int uV);
216
217 /* enable/disable regulator in suspend state */
218 int (*set_suspend_enable) (struct regulator_dev *);
219 int (*set_suspend_disable) (struct regulator_dev *);
220
Kim, Milofde297bb2012-02-16 22:41:32 -0800221 /* set regulator suspend operating mode (defined in consumer.h) */
Liam Girdwood571a3542008-04-30 15:42:28 +0100222 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
Stephen Boyd23c779b2015-06-11 17:37:04 -0700223
pascal paillet0380cf72018-07-05 14:25:57 +0000224 int (*resume)(struct regulator_dev *rdev);
Chunyan Zhangf7efad12018-01-26 21:08:47 +0800225
Stephen Boyd23c779b2015-06-11 17:37:04 -0700226 int (*set_pull_down) (struct regulator_dev *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100227};
228
229/*
230 * Regulators can either control voltage or current.
231 */
232enum regulator_type {
233 REGULATOR_VOLTAGE,
234 REGULATOR_CURRENT,
235};
236
237/**
Mark Brownc1727082012-04-04 00:50:22 +0100238 * struct regulator_desc - Static regulator descriptor
Liam Girdwood571a3542008-04-30 15:42:28 +0100239 *
Mark Brownc1727082012-04-04 00:50:22 +0100240 * Each regulator registered with the core is described with a
241 * structure of this type and a struct regulator_config. This
242 * structure contains the non-varying parts of the regulator
243 * description.
Mark Brownc8e7e462008-12-31 12:52:42 +0000244 *
245 * @name: Identifying name for the regulator.
Rajendra Nayak69511a42011-11-18 16:47:20 +0530246 * @supply_name: Identifying the regulator supply
Mark Browna0c7b162014-09-09 23:13:57 +0100247 * @of_match: Name used to identify regulator in DT.
248 * @regulators_node: Name of node containing regulator definitions in DT.
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100249 * @of_parse_cb: Optional callback called only if of_match is present.
250 * Will be called for each regulator parsed from DT, during
251 * init_data parsing.
252 * The regulator_config passed as argument to the callback will
253 * be a copy of config passed to regulator_register, valid only
254 * for this particular call. Callback may freely change the
255 * config but it cannot store it for later usage.
256 * Callback should return 0 on success or negative ERRNO
257 * indicating failure.
Mark Brownc8e7e462008-12-31 12:52:42 +0000258 * @id: Numerical identifier for the regulator.
259 * @ops: Regulator operations table.
Randy Dunlap0ba48872009-01-08 11:50:23 -0800260 * @irq: Interrupt number for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000261 * @type: Indicates if the regulator is a voltage or current regulator.
262 * @owner: Module providing the regulator, used for refcounting.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100263 *
Pawel Mollbd7a2b62012-09-24 18:56:53 +0100264 * @continuous_voltage_range: Indicates if the regulator can set any
265 * voltage within constrains range.
Mark Brownbca7bbf2012-05-09 21:38:33 +0100266 * @n_voltages: Number of selectors available for ops.list_voltage().
Axel Lina32e0c72019-02-28 21:40:13 +0800267 * @n_current_limits: Number of selectors available for current limits
Mark Brownbca7bbf2012-05-09 21:38:33 +0100268 *
269 * @min_uV: Voltage given by the lowest selector (if linear mapping)
270 * @uV_step: Voltage increase with each selector (if linear mapping)
Axel Lin33234e72012-11-27 10:24:33 +0800271 * @linear_min_sel: Minimal selector for starting linear mapping
Laxman Dewangan5a523602013-09-10 15:45:05 +0530272 * @fixed_uV: Fixed voltage of rails.
Axel Linea38d132012-06-18 14:03:16 +0800273 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200274 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700275 * @linear_ranges: A constant table of possible voltage ranges.
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300276 * @linear_range_selectors: A constant table of voltage range selectors.
277 * If pickable ranges are used each range must
278 * have corresponding selector here.
279 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
280 * linear_range_selectors if used) table(s).
Axel Lincffc9592012-05-20 10:30:21 +0800281 * @volt_table: Voltage mapping table (if table based mapping)
Axel Lina32e0c72019-02-28 21:40:13 +0800282 * @curr_table: Current limit mapping table (if table based mapping)
Mark Brownbca7bbf2012-05-09 21:38:33 +0100283 *
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300284 * @vsel_range_reg: Register for range selector when using pickable ranges
285 * and regulator_regmap_X_voltage_X_pickable functions.
286 * @vsel_range_mask: Mask for register bitfield used for range selector
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100287 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
288 * @vsel_mask: Mask for register bitfield used for selector
Axel Lin35d838f2019-02-28 21:40:12 +0800289 * @csel_reg: Register for current limit selector using regmap set_current_limit
290 * @csel_mask: Mask for register bitfield used for current limit selector
Axel Linc8520b42012-12-18 09:30:10 +0800291 * @apply_reg: Register for initiate voltage change on the output when
292 * using regulator_set_voltage_sel_regmap
293 * @apply_bit: Register bitfield used for initiate voltage change on the
294 * output when using regulator_set_voltage_sel_regmap
Mark Browncd6dffb2012-04-15 12:37:47 +0100295 * @enable_reg: Register for control when using regmap enable/disable ops
296 * @enable_mask: Mask for control when using regmap enable/disable ops
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100297 * @enable_val: Enabling value for control when using regmap enable/disable ops
298 * @disable_val: Disabling value for control when using regmap enable/disable ops
Axel Lin51dcdaf2013-03-05 14:16:00 +0800299 * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
300 * when using regulator_enable_regmap and friends APIs.
Nishanth Menon5838b032013-02-28 18:12:47 -0600301 * @bypass_reg: Register for control when using regmap set_bypass
302 * @bypass_mask: Mask for control when using regmap set_bypass
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100303 * @bypass_val_on: Enabling value for control when using regmap set_bypass
304 * @bypass_val_off: Disabling value for control when using regmap set_bypass
Laxman Dewangan354794d2016-03-02 16:24:47 +0530305 * @active_discharge_off: Enabling value for control when using regmap
306 * set_active_discharge
307 * @active_discharge_on: Disabling value for control when using regmap
308 * set_active_discharge
309 * @active_discharge_mask: Mask for control when using regmap
310 * set_active_discharge
311 * @active_discharge_reg: Register for control when using regmap
312 * set_active_discharge
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100313 * @soft_start_reg: Register for control when using regmap set_soft_start
314 * @soft_start_mask: Mask for control when using regmap set_soft_start
315 * @soft_start_val_on: Enabling value for control when using regmap
316 * set_soft_start
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100317 * @pull_down_reg: Register for control when using regmap set_pull_down
318 * @pull_down_mask: Mask for control when using regmap set_pull_down
319 * @pull_down_val_on: Enabling value for control when using regmap
320 * set_pull_down
Mark Brown79511ed2012-06-27 14:23:10 +0100321 *
322 * @enable_time: Time taken for initial enable of regulator (in uS).
Guodong Xu871f5652014-08-13 19:33:40 +0800323 * @off_on_delay: guard time (in uS), before re-enabling a regulator
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100324 *
325 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
Liam Girdwood571a3542008-04-30 15:42:28 +0100326 */
327struct regulator_desc {
328 const char *name;
Rajendra Nayak69511a42011-11-18 16:47:20 +0530329 const char *supply_name;
Mark Browna0c7b162014-09-09 23:13:57 +0100330 const char *of_match;
331 const char *regulators_node;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100332 int (*of_parse_cb)(struct device_node *,
333 const struct regulator_desc *,
334 struct regulator_config *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100335 int id;
Mark Brownde4a54c2016-01-21 20:19:41 +0000336 unsigned int continuous_voltage_range:1;
David Brownell4367cfd2009-02-26 11:48:36 -0800337 unsigned n_voltages;
Axel Lina32e0c72019-02-28 21:40:13 +0800338 unsigned int n_current_limits;
Axel Lindf11e502014-08-21 10:11:34 +0800339 const struct regulator_ops *ops;
Liam Girdwood571a3542008-04-30 15:42:28 +0100340 int irq;
341 enum regulator_type type;
342 struct module *owner;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100343
Mark Brownbca7bbf2012-05-09 21:38:33 +0100344 unsigned int min_uV;
345 unsigned int uV_step;
Axel Lin33234e72012-11-27 10:24:33 +0800346 unsigned int linear_min_sel;
Laxman Dewangan5a523602013-09-10 15:45:05 +0530347 int fixed_uV;
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530348 unsigned int ramp_delay;
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200349 int min_dropout_uV;
Mark Brownbca7bbf2012-05-09 21:38:33 +0100350
Mark Brown94d33c02013-07-02 22:52:41 +0100351 const struct regulator_linear_range *linear_ranges;
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300352 const unsigned int *linear_range_selectors;
353
Mark Brown94d33c02013-07-02 22:52:41 +0100354 int n_linear_ranges;
355
Axel Lincffc9592012-05-20 10:30:21 +0800356 const unsigned int *volt_table;
Axel Lina32e0c72019-02-28 21:40:13 +0800357 const unsigned int *curr_table;
Axel Lincffc9592012-05-20 10:30:21 +0800358
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300359 unsigned int vsel_range_reg;
360 unsigned int vsel_range_mask;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100361 unsigned int vsel_reg;
362 unsigned int vsel_mask;
Nikita Kiryanovc0ea88b2015-11-25 13:59:04 +0200363 unsigned int csel_reg;
364 unsigned int csel_mask;
Axel Linc8520b42012-12-18 09:30:10 +0800365 unsigned int apply_reg;
366 unsigned int apply_bit;
Mark Browncd6dffb2012-04-15 12:37:47 +0100367 unsigned int enable_reg;
368 unsigned int enable_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100369 unsigned int enable_val;
370 unsigned int disable_val;
Axel Lin51dcdaf2013-03-05 14:16:00 +0800371 bool enable_is_inverted;
Mark Browndf367932012-08-27 16:04:23 -0700372 unsigned int bypass_reg;
373 unsigned int bypass_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100374 unsigned int bypass_val_on;
375 unsigned int bypass_val_off;
Laxman Dewangan354794d2016-03-02 16:24:47 +0530376 unsigned int active_discharge_on;
377 unsigned int active_discharge_off;
378 unsigned int active_discharge_mask;
379 unsigned int active_discharge_reg;
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100380 unsigned int soft_start_reg;
381 unsigned int soft_start_mask;
382 unsigned int soft_start_val_on;
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100383 unsigned int pull_down_reg;
384 unsigned int pull_down_mask;
385 unsigned int pull_down_val_on;
Mark Brown79511ed2012-06-27 14:23:10 +0100386
387 unsigned int enable_time;
Guodong Xu871f5652014-08-13 19:33:40 +0800388
389 unsigned int off_on_delay;
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100390
391 unsigned int (*of_map_mode)(unsigned int mode);
Liam Girdwood571a3542008-04-30 15:42:28 +0100392};
393
Mark Brownc1727082012-04-04 00:50:22 +0100394/**
395 * struct regulator_config - Dynamic regulator descriptor
396 *
397 * Each regulator registered with the core is described with a
398 * structure of this type and a struct regulator_desc. This structure
399 * contains the runtime variable parts of the regulator description.
400 *
401 * @dev: struct device for the regulator
402 * @init_data: platform provided init data, passed through by driver
403 * @driver_data: private regulator data
404 * @of_node: OpenFirmware node to parse for device tree bindings (may be
405 * NULL).
Axel Lincf392842015-03-18 08:57:41 +0800406 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
Mark Brown380a0e62012-08-31 10:31:53 -0700407 * insufficient.
Linus Walleij541d0522019-01-29 11:31:56 +0100408 * @ena_gpiod: GPIO controlling regulator enable.
Mark Brownc1727082012-04-04 00:50:22 +0100409 */
410struct regulator_config {
411 struct device *dev;
412 const struct regulator_init_data *init_data;
413 void *driver_data;
414 struct device_node *of_node;
Mark Brown65b19ce2012-04-15 11:16:05 +0100415 struct regmap *regmap;
Mark Brown65f73502012-06-27 14:14:38 +0100416
Linus Walleije45e2902018-02-12 14:16:57 +0100417 struct gpio_desc *ena_gpiod;
Mark Brownc1727082012-04-04 00:50:22 +0100418};
419
Mark Brown1fa9ad52009-01-21 14:08:40 +0000420/*
Maciej Purskia085a312018-04-23 16:33:39 +0200421 * struct coupling_desc
422 *
423 * Describes coupling of regulators. Each regulator should have
424 * at least a pointer to itself in coupled_rdevs array.
425 * When a new coupled regulator is resolved, n_resolved is
426 * incremented.
427 */
428struct coupling_desc {
429 struct regulator_dev *coupled_rdevs[MAX_COUPLED];
430 int n_resolved;
431 int n_coupled;
432};
433
434/*
Mark Brown1fa9ad52009-01-21 14:08:40 +0000435 * struct regulator_dev
436 *
437 * Voltage / Current regulator class device. One for each
438 * regulator.
439 *
440 * This should *not* be used directly by anything except the regulator
441 * core and notification injection (which should take the mutex and do
442 * no other direct access).
443 */
444struct regulator_dev {
Mark Brown65f26842012-04-03 20:46:53 +0100445 const struct regulator_desc *desc;
Mark Brown5ffbd132009-07-21 16:00:23 +0100446 int exclusive;
Mark Brown1130e5b2010-12-21 23:49:31 +0000447 u32 use_count;
448 u32 open_count;
Mark Brownf59c8f92012-08-31 10:36:37 -0700449 u32 bypass_count;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000450
451 /* lists we belong to */
452 struct list_head list; /* list of all regulators */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000453
454 /* lists we own */
455 struct list_head consumer_list; /* consumers we supply */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000456
Maciej Purskia085a312018-04-23 16:33:39 +0200457 struct coupling_desc coupling_desc;
458
Mark Brown1fa9ad52009-01-21 14:08:40 +0000459 struct blocking_notifier_head notifier;
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300460 struct ww_mutex mutex; /* consumer lock */
Maciej Purski66cf9a72018-04-23 16:33:37 +0200461 struct task_struct *mutex_owner;
462 int ref_cnt;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000463 struct module *owner;
464 struct device dev;
465 struct regulation_constraints *constraints;
Mark Brown3801b862011-06-09 16:22:22 +0100466 struct regulator *supply; /* for tree */
Bjorn Andersson6261b062015-03-24 18:56:05 -0700467 const char *supply_name;
Mark Brown65b19ce2012-04-15 11:16:05 +0100468 struct regmap *regmap;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000469
Mark Brownda07ecd2011-09-11 09:53:50 +0100470 struct delayed_work disable_work;
Mark Brownda07ecd2011-09-11 09:53:50 +0100471
Mark Brown1fa9ad52009-01-21 14:08:40 +0000472 void *reg_data; /* regulator_dev data */
Mark Brown1130e5b2010-12-21 23:49:31 +0000473
Mark Brown1130e5b2010-12-21 23:49:31 +0000474 struct dentry *debugfs;
Mark Brown65f73502012-06-27 14:14:38 +0100475
Kim, Milof19b00d2013-02-18 06:50:39 +0000476 struct regulator_enable_gpio *ena_pin;
Mark Brown65f73502012-06-27 14:14:38 +0100477 unsigned int ena_gpio_state:1;
Guodong Xu871f5652014-08-13 19:33:40 +0800478
Matthias Kaehlckefd086042017-03-27 16:54:12 -0700479 unsigned int is_switch:1;
480
Guodong Xu871f5652014-08-13 19:33:40 +0800481 /* time when this regulator was disabled last time */
482 unsigned long last_off_jiffy;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000483};
484
Mark Brown65f26842012-04-03 20:46:53 +0100485struct regulator_dev *
486regulator_register(const struct regulator_desc *regulator_desc,
Mark Brownc1727082012-04-04 00:50:22 +0100487 const struct regulator_config *config);
Mark Brownb33e46b2013-08-31 11:58:26 +0100488struct regulator_dev *
489devm_regulator_register(struct device *dev,
490 const struct regulator_desc *regulator_desc,
491 const struct regulator_config *config);
Liam Girdwood571a3542008-04-30 15:42:28 +0100492void regulator_unregister(struct regulator_dev *rdev);
Mark Brownb33e46b2013-08-31 11:58:26 +0100493void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100494
495int regulator_notifier_call_chain(struct regulator_dev *rdev,
496 unsigned long event, void *data);
497
498void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100499struct device *rdev_get_dev(struct regulator_dev *rdev);
Bartosz Golaszewski03c87b92019-01-09 18:44:00 +0100500struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100501int rdev_get_id(struct regulator_dev *rdev);
502
Mark Brownbe721972009-08-04 20:09:52 +0200503int regulator_mode_to_status(unsigned int);
504
Mark Brownbca7bbf2012-05-09 21:38:33 +0100505int regulator_list_voltage_linear(struct regulator_dev *rdev,
506 unsigned int selector);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300507int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
508 unsigned int selector);
Mark Brown94d33c02013-07-02 22:52:41 +0100509int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
510 unsigned int selector);
Axel Lincffc9592012-05-20 10:30:21 +0800511int regulator_list_voltage_table(struct regulator_dev *rdev,
512 unsigned int selector);
Mark Brownbca7bbf2012-05-09 21:38:33 +0100513int regulator_map_voltage_linear(struct regulator_dev *rdev,
514 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300515int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
516 int min_uV, int max_uV);
Mark Brown94d33c02013-07-02 22:52:41 +0100517int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
518 int min_uV, int max_uV);
Mark Browne843fc42012-05-09 21:16:06 +0100519int regulator_map_voltage_iterate(struct regulator_dev *rdev,
520 int min_uV, int max_uV);
Axel Linfcf371e2013-04-18 10:34:49 +0800521int regulator_map_voltage_ascend(struct regulator_dev *rdev,
522 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300523int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
524int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
525 unsigned int sel);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100526int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
527int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
Mark Browncd6dffb2012-04-15 12:37:47 +0100528int regulator_is_enabled_regmap(struct regulator_dev *rdev);
529int regulator_enable_regmap(struct regulator_dev *rdev);
530int regulator_disable_regmap(struct regulator_dev *rdev);
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530531int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
532 unsigned int old_selector,
533 unsigned int new_selector);
Mark Browndf367932012-08-27 16:04:23 -0700534int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
535int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100536int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100537int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100538
Laxman Dewangan354794d2016-03-02 16:24:47 +0530539int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
540 bool enable);
Axel Lina32e0c72019-02-28 21:40:13 +0800541int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
542 int min_uA, int max_uA);
543int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100544void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
545
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300546void regulator_lock(struct regulator_dev *rdev);
547void regulator_unlock(struct regulator_dev *rdev);
548
Matti Vaittinen6a47b4d2019-02-14 11:38:05 +0200549/*
550 * Helper functions intended to be used by regulator drivers prior registering
551 * their regulators.
552 */
553int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
554 unsigned int selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100555#endif