blob: 5539efa76d2656c74b931e21abf3493a85404329 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Liam Girdwood4c1184e2008-04-30 15:46:09 +01002/*
3 * machine.h -- SoC Regulator support, machine/board driver API.
4 *
5 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6 *
Liam Girdwood1dd68f02009-02-02 21:43:31 +00007 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood4c1184e2008-04-30 15:46:09 +01008 *
Liam Girdwood4c1184e2008-04-30 15:46:09 +01009 * Regulator Machine/Board Interface.
10 */
11
12#ifndef __LINUX_REGULATOR_MACHINE_H_
13#define __LINUX_REGULATOR_MACHINE_H_
14
15#include <linux/regulator/consumer.h>
16#include <linux/suspend.h>
17
18struct regulator;
19
20/*
21 * Regulator operation constraint flags. These flags are used to enable
22 * certain regulator operations and can be OR'ed together.
23 *
24 * VOLTAGE: Regulator output voltage can be changed by software on this
25 * board/machine.
26 * CURRENT: Regulator output current can be changed by software on this
27 * board/machine.
28 * MODE: Regulator operating mode can be changed by software on this
29 * board/machine.
30 * STATUS: Regulator can be enabled and disabled.
31 * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator.
Mark Brownf59c8f92012-08-31 10:36:37 -070032 * BYPASS: Regulator can be put into bypass mode
Liam Girdwood4c1184e2008-04-30 15:46:09 +010033 */
34
35#define REGULATOR_CHANGE_VOLTAGE 0x1
36#define REGULATOR_CHANGE_CURRENT 0x2
37#define REGULATOR_CHANGE_MODE 0x4
38#define REGULATOR_CHANGE_STATUS 0x8
39#define REGULATOR_CHANGE_DRMS 0x10
Mark Brownf59c8f92012-08-31 10:36:37 -070040#define REGULATOR_CHANGE_BYPASS 0x20
Liam Girdwood4c1184e2008-04-30 15:46:09 +010041
Chunyan Zhang72069f92018-01-26 21:08:45 +080042/*
43 * operations in suspend mode
44 * DO_NOTHING_IN_SUSPEND - the default value
45 * DISABLE_IN_SUSPEND - turn off regulator in suspend states
46 * ENABLE_IN_SUSPEND - keep regulator on in suspend states
47 */
Marek Szyprowski3edd79c2018-09-03 16:49:37 +020048#define DO_NOTHING_IN_SUSPEND 0
49#define DISABLE_IN_SUSPEND 1
50#define ENABLE_IN_SUSPEND 2
Chunyan Zhang72069f92018-01-26 21:08:45 +080051
Laxman Dewangan670666b2016-03-02 16:24:46 +053052/* Regulator active discharge flags */
53enum regulator_active_discharge {
54 REGULATOR_ACTIVE_DISCHARGE_DEFAULT,
55 REGULATOR_ACTIVE_DISCHARGE_DISABLE,
56 REGULATOR_ACTIVE_DISCHARGE_ENABLE,
57};
58
Liam Girdwood4c1184e2008-04-30 15:46:09 +010059/**
Wolfram Sang2e7e65ce2009-09-18 22:44:43 +020060 * struct regulator_state - regulator state during low power system states
Liam Girdwood4c1184e2008-04-30 15:46:09 +010061 *
Mark Brown638f85c2009-10-22 16:31:33 +010062 * This describes a regulators state during a system wide low power
63 * state. One of enabled or disabled must be set for the
64 * configuration to be applied.
Mark Brownc8e7e462008-12-31 12:52:42 +000065 *
Chunyan Zhangf7efad12018-01-26 21:08:47 +080066 * @uV: Default operating voltage during suspend, it can be adjusted
67 * among <min_uV, max_uV>.
68 * @min_uV: Minimum suspend voltage may be set.
69 * @max_uV: Maximum suspend voltage may be set.
Mark Brownc8e7e462008-12-31 12:52:42 +000070 * @mode: Operating mode during suspend.
Chunyan Zhang72069f92018-01-26 21:08:45 +080071 * @enabled: operations during suspend.
72 * - DO_NOTHING_IN_SUSPEND
73 * - DISABLE_IN_SUSPEND
74 * - ENABLE_IN_SUSPEND
Chunyan Zhangf7efad12018-01-26 21:08:47 +080075 * @changeable: Is this state can be switched between enabled/disabled,
Liam Girdwood4c1184e2008-04-30 15:46:09 +010076 */
77struct regulator_state {
Chunyan Zhangf7efad12018-01-26 21:08:47 +080078 int uV;
79 int min_uV;
80 int max_uV;
81 unsigned int mode;
Chunyan Zhang72069f92018-01-26 21:08:45 +080082 int enabled;
Chunyan Zhangf7efad12018-01-26 21:08:47 +080083 bool changeable;
Liam Girdwood4c1184e2008-04-30 15:46:09 +010084};
85
86/**
87 * struct regulation_constraints - regulator operating constraints.
88 *
89 * This struct describes regulator and board/machine specific constraints.
Mark Brownc8e7e462008-12-31 12:52:42 +000090 *
91 * @name: Descriptive name for the constraints, used for display purposes.
92 *
93 * @min_uV: Smallest voltage consumers may set.
94 * @max_uV: Largest voltage consumers may set.
Mark Brownbf5892a2011-05-08 22:13:37 +010095 * @uV_offset: Offset applied to voltages from consumer to compensate for
96 * voltage drops.
Mark Brownc8e7e462008-12-31 12:52:42 +000097 *
Axel Lin15c08f62012-03-29 12:21:17 +080098 * @min_uA: Smallest current consumers may set.
Mark Brownc8e7e462008-12-31 12:52:42 +000099 * @max_uA: Largest current consumers may set.
Stephen Boyd36e4f832015-06-11 17:37:06 -0700100 * @ilim_uA: Maximum input current.
Stephen Boyd22a10bc2015-06-11 17:37:03 -0700101 * @system_load: Load that isn't captured by any consumer requests.
Mark Brownc8e7e462008-12-31 12:52:42 +0000102 *
Maciej Purskia085a312018-04-23 16:33:39 +0200103 * @max_spread: Max possible spread between coupled regulators
Mark Brownc8e7e462008-12-31 12:52:42 +0000104 * @valid_modes_mask: Mask of modes which may be configured by consumers.
105 * @valid_ops_mask: Operations which may be performed by consumers.
106 *
107 * @always_on: Set if the regulator should never be disabled.
108 * @boot_on: Set if the regulator is enabled when the system is initially
Mark Browncacf90f2009-03-02 16:32:46 +0000109 * started. If the regulator is not enabled by the hardware or
110 * bootloader then it will be enabled when the constraints are
111 * applied.
Mark Brownc8e7e462008-12-31 12:52:42 +0000112 * @apply_uV: Apply the voltage constraint when initialising.
Randy Dunlapa8dbfee2014-08-27 14:31:24 -0700113 * @ramp_disable: Disable ramp delay when initialising or when setting voltage.
Stephen Boydc751ad02015-06-12 15:48:06 -0700114 * @soft_start: Enable soft start so that voltage ramps slowly.
Stephen Boyd23c779b2015-06-11 17:37:04 -0700115 * @pull_down: Enable pull down when regulator is disabled.
Luis de Bethencourtabf2f822016-03-23 11:35:39 +0000116 * @over_current_protection: Auto disable on over current event.
Mark Brownc8e7e462008-12-31 12:52:42 +0000117 *
118 * @input_uV: Input voltage for regulator when supplied by another regulator.
119 *
120 * @state_disk: State for regulator when system is suspended in disk mode.
121 * @state_mem: State for regulator when system is suspended in mem mode.
122 * @state_standby: State for regulator when system is suspended in standby
123 * mode.
124 * @initial_state: Suspend state to set by default.
Mark Browna3084662009-02-26 19:24:19 +0000125 * @initial_mode: Mode to set at startup.
Axel Linea38d132012-06-18 14:03:16 +0800126 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
Laxman Dewangand6c1dc32017-04-04 18:59:50 +0530127 * @settling_time: Time to settle down after voltage change when voltage
128 * change is non-linear (unit: microseconds).
Matthias Kaehlcke3ffad462017-05-16 11:43:43 -0700129 * @settling_time_up: Time to settle down after voltage increase when voltage
130 * change is non-linear (unit: microseconds).
131 * @settling_time_down : Time to settle down after voltage decrease when
132 * voltage change is non-linear (unit: microseconds).
Laxman Dewangan670666b2016-03-02 16:24:46 +0530133 * @active_discharge: Enable/disable active discharge. The enum
134 * regulator_active_discharge values are used for
135 * initialisation.
Laxman Dewangan00c877c2013-09-18 18:18:02 +0530136 * @enable_time: Turn-on time of the rails (unit: microseconds)
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100137 */
138struct regulation_constraints {
139
Mark Brown01515462011-10-14 13:36:04 +0100140 const char *name;
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100141
142 /* voltage output range (inclusive) - for voltage control */
143 int min_uV;
144 int max_uV;
145
Mark Brownbf5892a2011-05-08 22:13:37 +0100146 int uV_offset;
147
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100148 /* current output range (inclusive) - for current control */
149 int min_uA;
150 int max_uA;
Stephen Boyd36e4f832015-06-11 17:37:06 -0700151 int ilim_uA;
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100152
Stephen Boyd22a10bc2015-06-11 17:37:03 -0700153 int system_load;
154
Maciej Purskia085a312018-04-23 16:33:39 +0200155 /* used for coupled regulators */
156 int max_spread;
157
Dmitry Osipenko85254bc2018-10-05 18:36:35 +0300158 /* used for changing voltage in steps */
159 int max_uV_step;
160
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100161 /* valid regulator operating modes for this machine */
162 unsigned int valid_modes_mask;
163
164 /* valid operations for regulator on this machine */
165 unsigned int valid_ops_mask;
166
167 /* regulator input voltage - only if supply is another regulator */
168 int input_uV;
169
170 /* regulator suspend states for global PMIC STANDBY/HIBERNATE */
171 struct regulator_state state_disk;
172 struct regulator_state state_mem;
173 struct regulator_state state_standby;
174 suspend_state_t initial_state; /* suspend state to set at init */
175
Mark Browna3084662009-02-26 19:24:19 +0000176 /* mode to set on startup */
177 unsigned int initial_mode;
178
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530179 unsigned int ramp_delay;
Laxman Dewangand6c1dc32017-04-04 18:59:50 +0530180 unsigned int settling_time;
Matthias Kaehlcke3ffad462017-05-16 11:43:43 -0700181 unsigned int settling_time_up;
182 unsigned int settling_time_down;
Laxman Dewangan00c877c2013-09-18 18:18:02 +0530183 unsigned int enable_time;
Yadwinder Singh Brar6f0b2c62012-06-11 17:41:08 +0530184
Laxman Dewangan670666b2016-03-02 16:24:46 +0530185 unsigned int active_discharge;
186
Wolfram Sang2e7e65ce2009-09-18 22:44:43 +0200187 /* constraint flags */
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100188 unsigned always_on:1; /* regulator never off when system is on */
189 unsigned boot_on:1; /* bootloader/firmware enabled regulator */
Wolfram Sang2e7e65ce2009-09-18 22:44:43 +0200190 unsigned apply_uV:1; /* apply uV constraint if min == max */
Yadwinder Singh Brar1653ccf2013-06-29 18:21:15 +0530191 unsigned ramp_disable:1; /* disable ramp delay */
Stephen Boyd57f66b72015-06-11 17:37:05 -0700192 unsigned soft_start:1; /* ramp voltage slowly */
Stephen Boyd23c779b2015-06-11 17:37:04 -0700193 unsigned pull_down:1; /* pull down resistor when regulator off */
Stephen Boyd3a003ba2015-07-17 14:41:54 -0700194 unsigned over_current_protection:1; /* auto disable on over current */
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100195};
196
Liam Girdwooda5766f12008-10-10 13:22:20 +0100197/**
198 * struct regulator_consumer_supply - supply -> device mapping
199 *
Axel Lin15c08f62012-03-29 12:21:17 +0800200 * This maps a supply name to a device. Use of dev_name allows support for
201 * buses which make struct device available late such as I2C.
Mark Brownc8e7e462008-12-31 12:52:42 +0000202 *
Mark Brown40f92442009-06-17 17:56:39 +0100203 * @dev_name: Result of dev_name() for the consumer.
Mark Brownc8e7e462008-12-31 12:52:42 +0000204 * @supply: Name for the supply.
Liam Girdwooda5766f12008-10-10 13:22:20 +0100205 */
206struct regulator_consumer_supply {
Mark Brown40f92442009-06-17 17:56:39 +0100207 const char *dev_name; /* dev_name() for consumer */
Liam Girdwooda5766f12008-10-10 13:22:20 +0100208 const char *supply; /* consumer supply - e.g. "vcc" */
209};
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100210
roalded654322009-07-13 17:25:21 +0800211/* Initialize struct regulator_consumer_supply */
212#define REGULATOR_SUPPLY(_name, _dev_name) \
213{ \
214 .supply = _name, \
215 .dev_name = _dev_name, \
216}
217
Liam Girdwooda5766f12008-10-10 13:22:20 +0100218/**
219 * struct regulator_init_data - regulator platform initialisation data.
220 *
221 * Initialisation constraints, our supply and consumers supplies.
Mark Brownc8e7e462008-12-31 12:52:42 +0000222 *
Mark Brown0178f3e2010-04-26 15:18:14 +0100223 * @supply_regulator: Parent regulator. Specified using the regulator name
224 * as it appears in the name field in sysfs, which can
225 * be explicitly set using the constraints field 'name'.
Mark Brownc8e7e462008-12-31 12:52:42 +0000226 *
227 * @constraints: Constraints. These must be specified for the regulator to
228 * be usable.
229 * @num_consumer_supplies: Number of consumer device supplies.
230 * @consumer_supplies: Consumer device supply configuration.
231 *
232 * @regulator_init: Callback invoked when the regulator has been registered.
233 * @driver_data: Data passed to regulator_init.
Liam Girdwooda5766f12008-10-10 13:22:20 +0100234 */
235struct regulator_init_data {
Mark Brown0178f3e2010-04-26 15:18:14 +0100236 const char *supply_regulator; /* or NULL for system supply */
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100237
Liam Girdwooda5766f12008-10-10 13:22:20 +0100238 struct regulation_constraints constraints;
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100239
Liam Girdwooda5766f12008-10-10 13:22:20 +0100240 int num_consumer_supplies;
241 struct regulator_consumer_supply *consumer_supplies;
242
243 /* optional regulator machine specific init */
244 int (*regulator_init)(void *driver_data);
245 void *driver_data; /* core does not touch this */
246};
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100247
Mark Brown9c19bc02009-07-09 15:44:31 +0100248#ifdef CONFIG_REGULATOR
Mark Brownca725562009-03-16 19:36:34 +0000249void regulator_has_full_constraints(void);
Mark Brown9c19bc02009-07-09 15:44:31 +0100250#else
251static inline void regulator_has_full_constraints(void)
252{
253}
Chunyan Zhangaa27bbc2018-01-26 21:08:46 +0800254#endif
255
Krzysztof Kozlowski50910272015-02-04 11:45:28 +0100256static inline int regulator_suspend_prepare(suspend_state_t state)
257{
258 return 0;
259}
260static inline int regulator_suspend_finish(void)
261{
262 return 0;
263}
Mark Brownca725562009-03-16 19:36:34 +0000264
Liam Girdwood4c1184e2008-04-30 15:46:09 +0100265#endif