blob: b9557c9623b5afc731204db8a485825606b606a7 [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().
267 *
268 * @min_uV: Voltage given by the lowest selector (if linear mapping)
269 * @uV_step: Voltage increase with each selector (if linear mapping)
Axel Lin33234e72012-11-27 10:24:33 +0800270 * @linear_min_sel: Minimal selector for starting linear mapping
Laxman Dewangan5a523602013-09-10 15:45:05 +0530271 * @fixed_uV: Fixed voltage of rails.
Axel Linea38d132012-06-18 14:03:16 +0800272 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Sascha Hauer5abe4f22015-10-13 12:45:26 +0200273 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700274 * @linear_ranges: A constant table of possible voltage ranges.
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300275 * @linear_range_selectors: A constant table of voltage range selectors.
276 * If pickable ranges are used each range must
277 * have corresponding selector here.
278 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
279 * linear_range_selectors if used) table(s).
Axel Lincffc9592012-05-20 10:30:21 +0800280 * @volt_table: Voltage mapping table (if table based mapping)
Mark Brownbca7bbf2012-05-09 21:38:33 +0100281 *
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300282 * @vsel_range_reg: Register for range selector when using pickable ranges
283 * and regulator_regmap_X_voltage_X_pickable functions.
284 * @vsel_range_mask: Mask for register bitfield used for range selector
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100285 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
286 * @vsel_mask: Mask for register bitfield used for selector
Axel Lin35d838f2019-02-28 21:40:12 +0800287 * @csel_reg: Register for current limit selector using regmap set_current_limit
288 * @csel_mask: Mask for register bitfield used for current limit selector
Axel Linc8520b42012-12-18 09:30:10 +0800289 * @apply_reg: Register for initiate voltage change on the output when
290 * using regulator_set_voltage_sel_regmap
291 * @apply_bit: Register bitfield used for initiate voltage change on the
292 * output when using regulator_set_voltage_sel_regmap
Mark Browncd6dffb2012-04-15 12:37:47 +0100293 * @enable_reg: Register for control when using regmap enable/disable ops
294 * @enable_mask: Mask for control when using regmap enable/disable ops
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100295 * @enable_val: Enabling value for control when using regmap enable/disable ops
296 * @disable_val: Disabling value for control when using regmap enable/disable ops
Axel Lin51dcdaf2013-03-05 14:16:00 +0800297 * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
298 * when using regulator_enable_regmap and friends APIs.
Nishanth Menon5838b032013-02-28 18:12:47 -0600299 * @bypass_reg: Register for control when using regmap set_bypass
300 * @bypass_mask: Mask for control when using regmap set_bypass
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100301 * @bypass_val_on: Enabling value for control when using regmap set_bypass
302 * @bypass_val_off: Disabling value for control when using regmap set_bypass
Laxman Dewangan354794d2016-03-02 16:24:47 +0530303 * @active_discharge_off: Enabling value for control when using regmap
304 * set_active_discharge
305 * @active_discharge_on: Disabling value for control when using regmap
306 * set_active_discharge
307 * @active_discharge_mask: Mask for control when using regmap
308 * set_active_discharge
309 * @active_discharge_reg: Register for control when using regmap
310 * set_active_discharge
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100311 * @soft_start_reg: Register for control when using regmap set_soft_start
312 * @soft_start_mask: Mask for control when using regmap set_soft_start
313 * @soft_start_val_on: Enabling value for control when using regmap
314 * set_soft_start
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100315 * @pull_down_reg: Register for control when using regmap set_pull_down
316 * @pull_down_mask: Mask for control when using regmap set_pull_down
317 * @pull_down_val_on: Enabling value for control when using regmap
318 * set_pull_down
Mark Brown79511ed2012-06-27 14:23:10 +0100319 *
320 * @enable_time: Time taken for initial enable of regulator (in uS).
Guodong Xu871f5652014-08-13 19:33:40 +0800321 * @off_on_delay: guard time (in uS), before re-enabling a regulator
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100322 *
323 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
Liam Girdwood571a3542008-04-30 15:42:28 +0100324 */
325struct regulator_desc {
326 const char *name;
Rajendra Nayak69511a42011-11-18 16:47:20 +0530327 const char *supply_name;
Mark Browna0c7b162014-09-09 23:13:57 +0100328 const char *of_match;
329 const char *regulators_node;
Krzysztof Kozlowskibfa21a02015-01-05 12:48:42 +0100330 int (*of_parse_cb)(struct device_node *,
331 const struct regulator_desc *,
332 struct regulator_config *);
Liam Girdwood571a3542008-04-30 15:42:28 +0100333 int id;
Mark Brownde4a54c2016-01-21 20:19:41 +0000334 unsigned int continuous_voltage_range:1;
David Brownell4367cfd2009-02-26 11:48:36 -0800335 unsigned n_voltages;
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;
354
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300355 unsigned int vsel_range_reg;
356 unsigned int vsel_range_mask;
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100357 unsigned int vsel_reg;
358 unsigned int vsel_mask;
Nikita Kiryanovc0ea88b2015-11-25 13:59:04 +0200359 unsigned int csel_reg;
360 unsigned int csel_mask;
Axel Linc8520b42012-12-18 09:30:10 +0800361 unsigned int apply_reg;
362 unsigned int apply_bit;
Mark Browncd6dffb2012-04-15 12:37:47 +0100363 unsigned int enable_reg;
364 unsigned int enable_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100365 unsigned int enable_val;
366 unsigned int disable_val;
Axel Lin51dcdaf2013-03-05 14:16:00 +0800367 bool enable_is_inverted;
Mark Browndf367932012-08-27 16:04:23 -0700368 unsigned int bypass_reg;
369 unsigned int bypass_mask;
Carlo Caioneca5d1b32014-03-05 22:11:29 +0100370 unsigned int bypass_val_on;
371 unsigned int bypass_val_off;
Laxman Dewangan354794d2016-03-02 16:24:47 +0530372 unsigned int active_discharge_on;
373 unsigned int active_discharge_off;
374 unsigned int active_discharge_mask;
375 unsigned int active_discharge_reg;
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100376 unsigned int soft_start_reg;
377 unsigned int soft_start_mask;
378 unsigned int soft_start_val_on;
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100379 unsigned int pull_down_reg;
380 unsigned int pull_down_mask;
381 unsigned int pull_down_val_on;
Mark Brown79511ed2012-06-27 14:23:10 +0100382
383 unsigned int enable_time;
Guodong Xu871f5652014-08-13 19:33:40 +0800384
385 unsigned int off_on_delay;
Javier Martinez Canillas87e1e0f2014-11-10 14:43:52 +0100386
387 unsigned int (*of_map_mode)(unsigned int mode);
Liam Girdwood571a3542008-04-30 15:42:28 +0100388};
389
Mark Brownc1727082012-04-04 00:50:22 +0100390/**
391 * struct regulator_config - Dynamic regulator descriptor
392 *
393 * Each regulator registered with the core is described with a
394 * structure of this type and a struct regulator_desc. This structure
395 * contains the runtime variable parts of the regulator description.
396 *
397 * @dev: struct device for the regulator
398 * @init_data: platform provided init data, passed through by driver
399 * @driver_data: private regulator data
400 * @of_node: OpenFirmware node to parse for device tree bindings (may be
401 * NULL).
Axel Lincf392842015-03-18 08:57:41 +0800402 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
Mark Brown380a0e62012-08-31 10:31:53 -0700403 * insufficient.
Linus Walleij541d0522019-01-29 11:31:56 +0100404 * @ena_gpiod: GPIO controlling regulator enable.
Mark Brownc1727082012-04-04 00:50:22 +0100405 */
406struct regulator_config {
407 struct device *dev;
408 const struct regulator_init_data *init_data;
409 void *driver_data;
410 struct device_node *of_node;
Mark Brown65b19ce2012-04-15 11:16:05 +0100411 struct regmap *regmap;
Mark Brown65f73502012-06-27 14:14:38 +0100412
Linus Walleije45e2902018-02-12 14:16:57 +0100413 struct gpio_desc *ena_gpiod;
Mark Brownc1727082012-04-04 00:50:22 +0100414};
415
Mark Brown1fa9ad52009-01-21 14:08:40 +0000416/*
Maciej Purskia085a312018-04-23 16:33:39 +0200417 * struct coupling_desc
418 *
419 * Describes coupling of regulators. Each regulator should have
420 * at least a pointer to itself in coupled_rdevs array.
421 * When a new coupled regulator is resolved, n_resolved is
422 * incremented.
423 */
424struct coupling_desc {
425 struct regulator_dev *coupled_rdevs[MAX_COUPLED];
426 int n_resolved;
427 int n_coupled;
428};
429
430/*
Mark Brown1fa9ad52009-01-21 14:08:40 +0000431 * struct regulator_dev
432 *
433 * Voltage / Current regulator class device. One for each
434 * regulator.
435 *
436 * This should *not* be used directly by anything except the regulator
437 * core and notification injection (which should take the mutex and do
438 * no other direct access).
439 */
440struct regulator_dev {
Mark Brown65f26842012-04-03 20:46:53 +0100441 const struct regulator_desc *desc;
Mark Brown5ffbd132009-07-21 16:00:23 +0100442 int exclusive;
Mark Brown1130e5b2010-12-21 23:49:31 +0000443 u32 use_count;
444 u32 open_count;
Mark Brownf59c8f92012-08-31 10:36:37 -0700445 u32 bypass_count;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000446
447 /* lists we belong to */
448 struct list_head list; /* list of all regulators */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000449
450 /* lists we own */
451 struct list_head consumer_list; /* consumers we supply */
Mark Brown1fa9ad52009-01-21 14:08:40 +0000452
Maciej Purskia085a312018-04-23 16:33:39 +0200453 struct coupling_desc coupling_desc;
454
Mark Brown1fa9ad52009-01-21 14:08:40 +0000455 struct blocking_notifier_head notifier;
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300456 struct ww_mutex mutex; /* consumer lock */
Maciej Purski66cf9a72018-04-23 16:33:37 +0200457 struct task_struct *mutex_owner;
458 int ref_cnt;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000459 struct module *owner;
460 struct device dev;
461 struct regulation_constraints *constraints;
Mark Brown3801b862011-06-09 16:22:22 +0100462 struct regulator *supply; /* for tree */
Bjorn Andersson6261b062015-03-24 18:56:05 -0700463 const char *supply_name;
Mark Brown65b19ce2012-04-15 11:16:05 +0100464 struct regmap *regmap;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000465
Mark Brownda07ecd2011-09-11 09:53:50 +0100466 struct delayed_work disable_work;
Mark Brownda07ecd2011-09-11 09:53:50 +0100467
Mark Brown1fa9ad52009-01-21 14:08:40 +0000468 void *reg_data; /* regulator_dev data */
Mark Brown1130e5b2010-12-21 23:49:31 +0000469
Mark Brown1130e5b2010-12-21 23:49:31 +0000470 struct dentry *debugfs;
Mark Brown65f73502012-06-27 14:14:38 +0100471
Kim, Milof19b00d2013-02-18 06:50:39 +0000472 struct regulator_enable_gpio *ena_pin;
Mark Brown65f73502012-06-27 14:14:38 +0100473 unsigned int ena_gpio_state:1;
Guodong Xu871f5652014-08-13 19:33:40 +0800474
Matthias Kaehlckefd086042017-03-27 16:54:12 -0700475 unsigned int is_switch:1;
476
Guodong Xu871f5652014-08-13 19:33:40 +0800477 /* time when this regulator was disabled last time */
478 unsigned long last_off_jiffy;
Mark Brown1fa9ad52009-01-21 14:08:40 +0000479};
480
Mark Brown65f26842012-04-03 20:46:53 +0100481struct regulator_dev *
482regulator_register(const struct regulator_desc *regulator_desc,
Mark Brownc1727082012-04-04 00:50:22 +0100483 const struct regulator_config *config);
Mark Brownb33e46b2013-08-31 11:58:26 +0100484struct regulator_dev *
485devm_regulator_register(struct device *dev,
486 const struct regulator_desc *regulator_desc,
487 const struct regulator_config *config);
Liam Girdwood571a3542008-04-30 15:42:28 +0100488void regulator_unregister(struct regulator_dev *rdev);
Mark Brownb33e46b2013-08-31 11:58:26 +0100489void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100490
491int regulator_notifier_call_chain(struct regulator_dev *rdev,
492 unsigned long event, void *data);
493
494void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100495struct device *rdev_get_dev(struct regulator_dev *rdev);
Bartosz Golaszewski03c87b92019-01-09 18:44:00 +0100496struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100497int rdev_get_id(struct regulator_dev *rdev);
498
Mark Brownbe721972009-08-04 20:09:52 +0200499int regulator_mode_to_status(unsigned int);
500
Mark Brownbca7bbf2012-05-09 21:38:33 +0100501int regulator_list_voltage_linear(struct regulator_dev *rdev,
502 unsigned int selector);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300503int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
504 unsigned int selector);
Mark Brown94d33c02013-07-02 22:52:41 +0100505int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
506 unsigned int selector);
Axel Lincffc9592012-05-20 10:30:21 +0800507int regulator_list_voltage_table(struct regulator_dev *rdev,
508 unsigned int selector);
Mark Brownbca7bbf2012-05-09 21:38:33 +0100509int regulator_map_voltage_linear(struct regulator_dev *rdev,
510 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300511int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
512 int min_uV, int max_uV);
Mark Brown94d33c02013-07-02 22:52:41 +0100513int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
514 int min_uV, int max_uV);
Mark Browne843fc42012-05-09 21:16:06 +0100515int regulator_map_voltage_iterate(struct regulator_dev *rdev,
516 int min_uV, int max_uV);
Axel Linfcf371e2013-04-18 10:34:49 +0800517int regulator_map_voltage_ascend(struct regulator_dev *rdev,
518 int min_uV, int max_uV);
Matti Vaittinen18e4b552018-09-14 11:31:36 +0300519int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
520int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
521 unsigned int sel);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100522int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
523int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
Mark Browncd6dffb2012-04-15 12:37:47 +0100524int regulator_is_enabled_regmap(struct regulator_dev *rdev);
525int regulator_enable_regmap(struct regulator_dev *rdev);
526int regulator_disable_regmap(struct regulator_dev *rdev);
Yadwinder Singh Brar98a175b2012-06-09 16:40:38 +0530527int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
528 unsigned int old_selector,
529 unsigned int new_selector);
Mark Browndf367932012-08-27 16:04:23 -0700530int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
531int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
Charles Keepaxa7a453f2017-03-28 15:14:40 +0100532int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
Charles Keepaxf7d37bc2017-03-28 15:14:41 +0100533int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
Mark Brown4ab5b3d2012-04-15 11:23:30 +0100534
Laxman Dewangan354794d2016-03-02 16:24:47 +0530535int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
536 bool enable);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100537void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
538
Dmitry Osipenkof8702f92018-11-19 00:56:17 +0300539void regulator_lock(struct regulator_dev *rdev);
540void regulator_unlock(struct regulator_dev *rdev);
541
Matti Vaittinen6a47b4d2019-02-14 11:38:05 +0200542/*
543 * Helper functions intended to be used by regulator drivers prior registering
544 * their regulators.
545 */
546int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
547 unsigned int selector);
Liam Girdwood571a3542008-04-30 15:42:28 +0100548#endif