Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * driver.h -- SoC Regulator driver support.
4 *
5 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6 *
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 *
9 * Regulator Driver Interface.
10 */
11
12#ifndef __LINUX_REGULATOR_DRIVER_H_
13#define __LINUX_REGULATOR_DRIVER_H_
14
15#include <linux/device.h>
16#include <linux/linear_range.h>
17#include <linux/notifier.h>
18#include <linux/regulator/consumer.h>
19#include <linux/ww_mutex.h>
20
21struct gpio_desc;
22struct regmap;
23struct regulator_dev;
24struct regulator_config;
25struct regulator_init_data;
26struct regulator_enable_gpio;
27
28enum regulator_status {
29 REGULATOR_STATUS_OFF,
30 REGULATOR_STATUS_ON,
31 REGULATOR_STATUS_ERROR,
32 /* fast/normal/idle/standby are flavors of "on" */
33 REGULATOR_STATUS_FAST,
34 REGULATOR_STATUS_NORMAL,
35 REGULATOR_STATUS_IDLE,
36 REGULATOR_STATUS_STANDBY,
37 /* The regulator is enabled but not regulating */
38 REGULATOR_STATUS_BYPASS,
39 /* in case that any other status doesn't apply */
40 REGULATOR_STATUS_UNDEFINED,
41};
42
43enum regulator_detection_severity {
44 /* Hardware shut down voltage outputs if condition is detected */
45 REGULATOR_SEVERITY_PROT,
46 /* Hardware is probably damaged/inoperable */
47 REGULATOR_SEVERITY_ERR,
48 /* Hardware is still recoverable but recovery action must be taken */
49 REGULATOR_SEVERITY_WARN,
50};
51
52/* Initialize struct linear_range for regulators */
53#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
54 LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV)
55
56/* Initialize struct linear_range using voltages, not selectors */
57#define REGULATOR_LINEAR_VRANGE(_offs_uV, _min_uV, _max_uV, _step_uV) \
58 LINEAR_RANGE(_min_uV, ((_min_uV) - (_offs_uV)) / (_step_uV), \
59 ((_max_uV) - (_offs_uV)) / (_step_uV), _step_uV)
60
61/**
62 * struct regulator_ops - regulator operations.
63 *
64 * @enable: Configure the regulator as enabled.
65 * @disable: Configure the regulator as disabled.
66 * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
67 * May also return negative errno.
68 *
69 * @set_voltage: Set the voltage for the regulator within the range specified.
70 * The driver should select the voltage closest to min_uV.
71 * @set_voltage_sel: Set the voltage for the regulator using the specified
72 * selector.
73 * @map_voltage: Convert a voltage into a selector
74 * @get_voltage: Return the currently configured voltage for the regulator;
75 * return -ENOTRECOVERABLE if regulator can't be read at
76 * bootup and hasn't been set yet.
77 * @get_voltage_sel: Return the currently configured voltage selector for the
78 * regulator; return -ENOTRECOVERABLE if regulator can't
79 * be read at bootup and hasn't been set yet.
80 * @list_voltage: Return one of the supported voltages, in microvolts; zero
81 * if the selector indicates a voltage that is unusable on this system;
82 * or negative errno. Selectors range from zero to one less than
83 * regulator_desc.n_voltages. Voltages may be reported in any order.
84 *
85 * @set_current_limit: Configure a limit for a current-limited regulator.
86 * The driver should select the current closest to max_uA.
87 * @get_current_limit: Get the configured limit for a current-limited regulator.
88 * @set_input_current_limit: Configure an input limit.
89 *
90 * @set_over_current_protection: Support enabling of and setting limits for over
91 * current situation detection. Detection can be configured for three
92 * levels of severity.
93 *
94 * - REGULATOR_SEVERITY_PROT should automatically shut down the regulator(s).
95 *
96 * - REGULATOR_SEVERITY_ERR should indicate that over-current situation is
97 * caused by an unrecoverable error but HW does not perform
98 * automatic shut down.
99 *
100 * - REGULATOR_SEVERITY_WARN should indicate situation where hardware is
101 * still believed to not be damaged but that a board sepcific
102 * recovery action is needed. If lim_uA is 0 the limit should not
103 * be changed but the detection should just be enabled/disabled as
104 * is requested.
105 *
106 * @set_over_voltage_protection: Support enabling of and setting limits for over
107 * voltage situation detection. Detection can be configured for same
108 * severities as over current protection. Units of uV.
109 * @set_under_voltage_protection: Support enabling of and setting limits for
110 * under voltage situation detection. Detection can be configured for same
111 * severities as over current protection. Units of uV.
112 * @set_thermal_protection: Support enabling of and setting limits for over
113 * temperature situation detection.Detection can be configured for same
114 * severities as over current protection. Units of degree Kelvin.
115 *
116 * @set_active_discharge: Set active discharge enable/disable of regulators.
117 *
118 * @set_mode: Set the configured operating mode for the regulator.
119 * @get_mode: Get the configured operating mode for the regulator.
120 * @get_error_flags: Get the current error(s) for the regulator.
121 * @get_status: Return actual (not as-configured) status of regulator, as a
122 * REGULATOR_STATUS value (or negative errno)
123 * @get_optimum_mode: Get the most efficient operating mode for the regulator
124 * when running with the specified parameters.
125 * @set_load: Set the load for the regulator.
126 *
127 * @set_bypass: Set the regulator in bypass mode.
128 * @get_bypass: Get the regulator bypass mode state.
129 *
130 * @enable_time: Time taken for the regulator voltage output voltage to
131 * stabilise after being enabled, in microseconds.
132 * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
133 * select ramp delay equal to or less than(closest) ramp_delay.
134 * @set_voltage_time: Time taken for the regulator voltage output voltage
135 * to stabilise after being set to a new value, in microseconds.
136 * The function receives the from and to voltage as input, it
137 * should return the worst case.
138 * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
139 * to stabilise after being set to a new value, in microseconds.
140 * The function receives the from and to voltage selector as
141 * input, it should return the worst case.
142 * @set_soft_start: Enable soft start for the regulator.
143 *
144 * @set_suspend_voltage: Set the voltage for the regulator when the system
145 * is suspended.
146 * @set_suspend_enable: Mark the regulator as enabled when the system is
147 * suspended.
148 * @set_suspend_disable: Mark the regulator as disabled when the system is
149 * suspended.
150 * @set_suspend_mode: Set the operating mode for the regulator when the
151 * system is suspended.
152 * @resume: Resume operation of suspended regulator.
153 * @set_pull_down: Configure the regulator to pull down when the regulator
154 * is disabled.
155 *
156 * This struct describes regulator operations which can be implemented by
157 * regulator chip drivers.
158 */
159struct regulator_ops {
160
161 /* enumerate supported voltages */
162 int (*list_voltage) (struct regulator_dev *, unsigned selector);
163
164 /* get/set regulator voltage */
165 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
166 unsigned *selector);
167 int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
168 int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
169 int (*get_voltage) (struct regulator_dev *);
170 int (*get_voltage_sel) (struct regulator_dev *);
171
172 /* get/set regulator current */
173 int (*set_current_limit) (struct regulator_dev *,
174 int min_uA, int max_uA);
175 int (*get_current_limit) (struct regulator_dev *);
176
177 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
178 int (*set_over_current_protection)(struct regulator_dev *, int lim_uA,
179 int severity, bool enable);
180 int (*set_over_voltage_protection)(struct regulator_dev *, int lim_uV,
181 int severity, bool enable);
182 int (*set_under_voltage_protection)(struct regulator_dev *, int lim_uV,
183 int severity, bool enable);
184 int (*set_thermal_protection)(struct regulator_dev *, int lim,
185 int severity, bool enable);
186 int (*set_active_discharge)(struct regulator_dev *, bool enable);
187
188 /* enable/disable regulator */
189 int (*enable) (struct regulator_dev *);
190 int (*disable) (struct regulator_dev *);
191 int (*is_enabled) (struct regulator_dev *);
192
193 /* get/set regulator operating mode (defined in consumer.h) */
194 int (*set_mode) (struct regulator_dev *, unsigned int mode);
195 unsigned int (*get_mode) (struct regulator_dev *);
196
197 /* retrieve current error flags on the regulator */
198 int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
199
200 /* Time taken to enable or set voltage on the regulator */
201 int (*enable_time) (struct regulator_dev *);
202 int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
203 int (*set_voltage_time) (struct regulator_dev *, int old_uV,
204 int new_uV);
205 int (*set_voltage_time_sel) (struct regulator_dev *,
206 unsigned int old_selector,
207 unsigned int new_selector);
208
209 int (*set_soft_start) (struct regulator_dev *);
210
211 /* report regulator status ... most other accessors report
212 * control inputs, this reports results of combining inputs
213 * from Linux (and other sources) with the actual load.
214 * returns REGULATOR_STATUS_* or negative errno.
215 */
216 int (*get_status)(struct regulator_dev *);
217
218 /* get most efficient regulator operating mode for load */
219 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
220 int output_uV, int load_uA);
221 /* set the load on the regulator */
222 int (*set_load)(struct regulator_dev *, int load_uA);
223
224 /* control and report on bypass mode */
225 int (*set_bypass)(struct regulator_dev *dev, bool enable);
226 int (*get_bypass)(struct regulator_dev *dev, bool *enable);
227
228 /* the operations below are for configuration of regulator state when
229 * its parent PMIC enters a global STANDBY/HIBERNATE state */
230
231 /* set regulator suspend voltage */
232 int (*set_suspend_voltage) (struct regulator_dev *, int uV);
233
234 /* enable/disable regulator in suspend state */
235 int (*set_suspend_enable) (struct regulator_dev *);
236 int (*set_suspend_disable) (struct regulator_dev *);
237
238 /* set regulator suspend operating mode (defined in consumer.h) */
239 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
240
241 int (*resume)(struct regulator_dev *rdev);
242
243 int (*set_pull_down) (struct regulator_dev *);
244};
245
246/*
247 * Regulators can either control voltage or current.
248 */
249enum regulator_type {
250 REGULATOR_VOLTAGE,
251 REGULATOR_CURRENT,
252};
253
254/**
255 * struct regulator_desc - Static regulator descriptor
256 *
257 * Each regulator registered with the core is described with a
258 * structure of this type and a struct regulator_config. This
259 * structure contains the non-varying parts of the regulator
260 * description.
261 *
262 * @name: Identifying name for the regulator.
263 * @supply_name: Identifying the regulator supply
264 * @of_match: Name used to identify regulator in DT.
265 * @of_match_full_name: A flag to indicate that the of_match string, if
266 * present, should be matched against the node full_name.
267 * @regulators_node: Name of node containing regulator definitions in DT.
268 * @of_parse_cb: Optional callback called only if of_match is present.
269 * Will be called for each regulator parsed from DT, during
270 * init_data parsing.
271 * The regulator_config passed as argument to the callback will
272 * be a copy of config passed to regulator_register, valid only
273 * for this particular call. Callback may freely change the
274 * config but it cannot store it for later usage.
275 * Callback should return 0 on success or negative ERRNO
276 * indicating failure.
277 * @init_cb: Optional callback called after the parsing of init_data.
278 * Allows the regulator to perform runtime init if necessary,
279 * such as synching the regulator and the parsed constraints.
280 * Callback should return 0 on success or negative ERRNO
281 * indicating failure.
282 * @id: Numerical identifier for the regulator.
283 * @ops: Regulator operations table.
284 * @irq: Interrupt number for the regulator.
285 * @type: Indicates if the regulator is a voltage or current regulator.
286 * @owner: Module providing the regulator, used for refcounting.
287 *
288 * @continuous_voltage_range: Indicates if the regulator can set any
289 * voltage within constrains range.
290 * @n_voltages: Number of selectors available for ops.list_voltage().
291 * @n_current_limits: Number of selectors available for current limits
292 *
293 * @min_uV: Voltage given by the lowest selector (if linear mapping)
294 * @uV_step: Voltage increase with each selector (if linear mapping)
295 * @linear_min_sel: Minimal selector for starting linear mapping
296 * @fixed_uV: Fixed voltage of rails.
297 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
298 * @min_dropout_uV: The minimum dropout voltage this regulator can handle
299 * @linear_ranges: A constant table of possible voltage ranges.
300 * @linear_range_selectors_bitfield: A constant table of voltage range
301 * selectors as bitfield values. If
302 * pickable ranges are used each range
303 * must have corresponding selector here.
304 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
305 * linear_range_selectors_bitfield if used) table(s).
306 * @volt_table: Voltage mapping table (if table based mapping)
307 * @curr_table: Current limit mapping table (if table based mapping)
308 *
309 * @vsel_range_reg: Register for range selector when using pickable ranges
310 * and ``regulator_map_*_voltage_*_pickable`` functions.
311 * @vsel_range_mask: Mask for register bitfield used for range selector
312 * @range_applied_by_vsel: A flag to indicate that changes to vsel_range_reg
313 * are only effective after vsel_reg is written
314 * @vsel_reg: Register for selector when using ``regulator_map_*_voltage_*``
315 * @vsel_mask: Mask for register bitfield used for selector
316 * @vsel_step: Specify the resolution of selector stepping when setting
317 * voltage. If 0, then no stepping is done (requested selector is
318 * set directly), if >0 then the regulator API will ramp the
319 * voltage up/down gradually each time increasing/decreasing the
320 * selector by the specified step value.
321 * @csel_reg: Register for current limit selector using regmap set_current_limit
322 * @csel_mask: Mask for register bitfield used for current limit selector
323 * @apply_reg: Register for initiate voltage change on the output when
324 * using regulator_set_voltage_sel_regmap
325 * @apply_bit: Register bitfield used for initiate voltage change on the
326 * output when using regulator_set_voltage_sel_regmap
327 * @enable_reg: Register for control when using regmap enable/disable ops
328 * @enable_mask: Mask for control when using regmap enable/disable ops
329 * @enable_val: Enabling value for control when using regmap enable/disable ops
330 * @disable_val: Disabling value for control when using regmap enable/disable ops
331 * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
332 * when using regulator_enable_regmap and friends APIs.
333 * @bypass_reg: Register for control when using regmap set_bypass
334 * @bypass_mask: Mask for control when using regmap set_bypass
335 * @bypass_val_on: Enabling value for control when using regmap set_bypass
336 * @bypass_val_off: Disabling value for control when using regmap set_bypass
337 * @active_discharge_off: Enabling value for control when using regmap
338 * set_active_discharge
339 * @active_discharge_on: Disabling value for control when using regmap
340 * set_active_discharge
341 * @active_discharge_mask: Mask for control when using regmap
342 * set_active_discharge
343 * @active_discharge_reg: Register for control when using regmap
344 * set_active_discharge
345 * @soft_start_reg: Register for control when using regmap set_soft_start
346 * @soft_start_mask: Mask for control when using regmap set_soft_start
347 * @soft_start_val_on: Enabling value for control when using regmap
348 * set_soft_start
349 * @pull_down_reg: Register for control when using regmap set_pull_down
350 * @pull_down_mask: Mask for control when using regmap set_pull_down
351 * @pull_down_val_on: Enabling value for control when using regmap
352 * set_pull_down
353 *
354 * @ramp_reg: Register for controlling the regulator ramp-rate.
355 * @ramp_mask: Bitmask for the ramp-rate control register.
356 * @ramp_delay_table: Table for mapping the regulator ramp-rate values. Values
357 * should be given in units of V/S (uV/uS). See the
358 * regulator_set_ramp_delay_regmap().
359 * @n_ramp_values: number of elements at @ramp_delay_table.
360 *
361 * @enable_time: Time taken for initial enable of regulator (in uS).
362 * @off_on_delay: guard time (in uS), before re-enabling a regulator
363 *
364 * @poll_enabled_time: The polling interval (in uS) to use while checking that
365 * the regulator was actually enabled. Max upto enable_time.
366 *
367 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
368 */
369struct regulator_desc {
370 const char *name;
371 const char *supply_name;
372 const char *of_match;
373 bool of_match_full_name;
374 const char *regulators_node;
375 int (*of_parse_cb)(struct device_node *,
376 const struct regulator_desc *,
377 struct regulator_config *);
378 int (*init_cb)(struct regulator_dev *,
379 struct regulator_config *);
380 int id;
381 unsigned int continuous_voltage_range:1;
382 unsigned n_voltages;
383 unsigned int n_current_limits;
384 const struct regulator_ops *ops;
385 int irq;
386 enum regulator_type type;
387 struct module *owner;
388
389 unsigned int min_uV;
390 unsigned int uV_step;
391 unsigned int linear_min_sel;
392 int fixed_uV;
393 unsigned int ramp_delay;
394 int min_dropout_uV;
395
396 const struct linear_range *linear_ranges;
397 const unsigned int *linear_range_selectors_bitfield;
398
399 int n_linear_ranges;
400
401 const unsigned int *volt_table;
402 const unsigned int *curr_table;
403
404 unsigned int vsel_range_reg;
405 unsigned int vsel_range_mask;
406 bool range_applied_by_vsel;
407 unsigned int vsel_reg;
408 unsigned int vsel_mask;
409 unsigned int vsel_step;
410 unsigned int csel_reg;
411 unsigned int csel_mask;
412 unsigned int apply_reg;
413 unsigned int apply_bit;
414 unsigned int enable_reg;
415 unsigned int enable_mask;
416 unsigned int enable_val;
417 unsigned int disable_val;
418 bool enable_is_inverted;
419 unsigned int bypass_reg;
420 unsigned int bypass_mask;
421 unsigned int bypass_val_on;
422 unsigned int bypass_val_off;
423 unsigned int active_discharge_on;
424 unsigned int active_discharge_off;
425 unsigned int active_discharge_mask;
426 unsigned int active_discharge_reg;
427 unsigned int soft_start_reg;
428 unsigned int soft_start_mask;
429 unsigned int soft_start_val_on;
430 unsigned int pull_down_reg;
431 unsigned int pull_down_mask;
432 unsigned int pull_down_val_on;
433 unsigned int ramp_reg;
434 unsigned int ramp_mask;
435 const unsigned int *ramp_delay_table;
436 unsigned int n_ramp_values;
437
438 unsigned int enable_time;
439
440 unsigned int off_on_delay;
441
442 unsigned int poll_enabled_time;
443
444 unsigned int (*of_map_mode)(unsigned int mode);
445};
446
447/**
448 * struct regulator_config - Dynamic regulator descriptor
449 *
450 * Each regulator registered with the core is described with a
451 * structure of this type and a struct regulator_desc. This structure
452 * contains the runtime variable parts of the regulator description.
453 *
454 * @dev: struct device for the regulator
455 * @init_data: platform provided init data, passed through by driver
456 * @driver_data: private regulator data
457 * @of_node: OpenFirmware node to parse for device tree bindings (may be
458 * NULL).
459 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
460 * insufficient.
461 * @ena_gpiod: GPIO controlling regulator enable.
462 */
463struct regulator_config {
464 struct device *dev;
465 const struct regulator_init_data *init_data;
466 void *driver_data;
467 struct device_node *of_node;
468 struct regmap *regmap;
469
470 struct gpio_desc *ena_gpiod;
471};
472
473/**
474 * struct regulator_err_state - regulator error/notification status
475 *
476 * @rdev: Regulator which status the struct indicates.
477 * @notifs: Events which have occurred on the regulator.
478 * @errors: Errors which are active on the regulator.
479 * @possible_errs: Errors which can be signaled (by given IRQ).
480 */
481struct regulator_err_state {
482 struct regulator_dev *rdev;
483 unsigned long notifs;
484 unsigned long errors;
485 int possible_errs;
486};
487
488/**
489 * struct regulator_irq_data - regulator error/notification status data
490 *
491 * @states: Status structs for each of the associated regulators.
492 * @num_states: Amount of associated regulators.
493 * @data: Driver data pointer given at regulator_irq_desc.
494 * @opaque: Value storage for IC driver. Core does not update this. ICs
495 * may want to store status register value here at map_event and
496 * compare contents at 'renable' callback to see if new problems
497 * have been added to status. If that is the case it may be
498 * desirable to return REGULATOR_ERROR_CLEARED and not
499 * REGULATOR_ERROR_ON to allow IRQ fire again and to generate
500 * notifications also for the new issues.
501 *
502 * This structure is passed to 'map_event' and 'renable' callbacks for
503 * reporting regulator status to core.
504 */
505struct regulator_irq_data {
506 struct regulator_err_state *states;
507 int num_states;
508 void *data;
509 long opaque;
510};
511
512/**
513 * struct regulator_irq_desc - notification sender for IRQ based events.
514 *
515 * @name: The visible name for the IRQ
516 * @fatal_cnt: If this IRQ is used to signal HW damaging condition it may be
517 * best to shut-down regulator(s) or reboot the SOC if error
518 * handling is repeatedly failing. If fatal_cnt is given the IRQ
519 * handling is aborted if it fails for fatal_cnt times and die()
520 * callback (if populated) is called. If die() is not populated
521 * poweroff for the system is attempted in order to prevent any
522 * further damage.
523 * @reread_ms: The time which is waited before attempting to re-read status
524 * at the worker if IC reading fails. Immediate re-read is done
525 * if time is not specified.
526 * @irq_off_ms: The time which IRQ is kept disabled before re-evaluating the
527 * status for devices which keep IRQ disabled for duration of the
528 * error. If this is not given the IRQ is left enabled and renable
529 * is not called.
530 * @skip_off: If set to true the IRQ handler will attempt to check if any of
531 * the associated regulators are enabled prior to taking other
532 * actions. If no regulators are enabled and this is set to true
533 * a spurious IRQ is assumed and IRQ_NONE is returned.
534 * @high_prio: Boolean to indicate that high priority WQ should be used.
535 * @data: Driver private data pointer which will be passed as such to
536 * the renable, map_event and die callbacks in regulator_irq_data.
537 * @die: Protection callback. If IC status reading or recovery actions
538 * fail fatal_cnt times this callback is called or system is
539 * powered off. This callback should implement a final protection
540 * attempt like disabling the regulator. If protection succeeded
541 * die() may return 0. If anything else is returned the core
542 * assumes final protection failed and attempts to perform a
543 * poweroff as a last resort.
544 * @map_event: Driver callback to map IRQ status into regulator devices with
545 * events / errors. NOTE: callback MUST initialize both the
546 * errors and notifs for all rdevs which it signals having
547 * active events as core does not clean the map data.
548 * REGULATOR_FAILED_RETRY can be returned to indicate that the
549 * status reading from IC failed. If this is repeated for
550 * fatal_cnt times the core will call die() callback or power-off
551 * the system as a last resort to protect the HW.
552 * @renable: Optional callback to check status (if HW supports that) before
553 * re-enabling IRQ. If implemented this should clear the error
554 * flags so that errors fetched by regulator_get_error_flags()
555 * are updated. If callback is not implemented then errors are
556 * assumed to be cleared and IRQ is re-enabled.
557 * REGULATOR_FAILED_RETRY can be returned to
558 * indicate that the status reading from IC failed. If this is
559 * repeated for 'fatal_cnt' times the core will call die()
560 * callback or if die() is not populated then attempt to power-off
561 * the system as a last resort to protect the HW.
562 * Returning zero indicates that the problem in HW has been solved
563 * and IRQ will be re-enabled. Returning REGULATOR_ERROR_ON
564 * indicates the error condition is still active and keeps IRQ
565 * disabled. Please note that returning REGULATOR_ERROR_ON does
566 * not retrigger evaluating what events are active or resending
567 * notifications. If this is needed you probably want to return
568 * zero and allow IRQ to retrigger causing events to be
569 * re-evaluated and re-sent.
570 *
571 * This structure is used for registering regulator IRQ notification helper.
572 */
573struct regulator_irq_desc {
574 const char *name;
575 int fatal_cnt;
576 int reread_ms;
577 int irq_off_ms;
578 bool skip_off;
579 bool high_prio;
580 void *data;
581
582 int (*die)(struct regulator_irq_data *rid);
583 int (*map_event)(int irq, struct regulator_irq_data *rid,
584 unsigned long *dev_mask);
585 int (*renable)(struct regulator_irq_data *rid);
586};
587
588/*
589 * Return values for regulator IRQ helpers.
590 */
591enum {
592 REGULATOR_ERROR_CLEARED,
593 REGULATOR_FAILED_RETRY,
594 REGULATOR_ERROR_ON,
595};
596
597/*
598 * struct coupling_desc
599 *
600 * Describes coupling of regulators. Each regulator should have
601 * at least a pointer to itself in coupled_rdevs array.
602 * When a new coupled regulator is resolved, n_resolved is
603 * incremented.
604 */
605struct coupling_desc {
606 struct regulator_dev **coupled_rdevs;
607 struct regulator_coupler *coupler;
608 int n_resolved;
609 int n_coupled;
610};
611
612/*
613 * struct regulator_dev
614 *
615 * Voltage / Current regulator class device. One for each
616 * regulator.
617 *
618 * This should *not* be used directly by anything except the regulator
619 * core and notification injection (which should take the mutex and do
620 * no other direct access).
621 */
622struct regulator_dev {
623 const struct regulator_desc *desc;
624 int exclusive;
625 u32 use_count;
626 u32 open_count;
627 u32 bypass_count;
628
629 /* lists we belong to */
630 struct list_head list; /* list of all regulators */
631
632 /* lists we own */
633 struct list_head consumer_list; /* consumers we supply */
634
635 struct coupling_desc coupling_desc;
636
637 struct blocking_notifier_head notifier;
638 struct ww_mutex mutex; /* consumer lock */
639 struct task_struct *mutex_owner;
640 int ref_cnt;
641 struct module *owner;
642 struct device dev;
643 struct device bdev;
644 struct regulation_constraints *constraints;
645 struct regulator *supply; /* for tree */
646 const char *supply_name;
647 struct regmap *regmap;
648
649 struct delayed_work disable_work;
650
651 void *reg_data; /* regulator_dev data */
652
653 struct dentry *debugfs;
654
655 struct regulator_enable_gpio *ena_pin;
656 unsigned int ena_gpio_state:1;
657
658 unsigned int constraints_pending:1;
659 unsigned int is_switch:1;
660
661 /* time when this regulator was disabled last time */
662 ktime_t last_off;
663 int cached_err;
664 bool use_cached_err;
665 spinlock_t err_lock;
666
667 int pw_requested_mW;
668
669 /* regulator notification forwarding */
670 struct notifier_block supply_fwd_nb;
671};
672
673/*
674 * Convert error flags to corresponding notifications.
675 *
676 * Can be used by drivers which use the notification helpers to
677 * find out correct notification flags based on the error flags. Drivers
678 * can avoid storing both supported notification and error flags which
679 * may save few bytes.
680 */
681static inline int regulator_err2notif(int err)
682{
683 switch (err) {
684 case REGULATOR_ERROR_UNDER_VOLTAGE:
685 return REGULATOR_EVENT_UNDER_VOLTAGE;
686 case REGULATOR_ERROR_OVER_CURRENT:
687 return REGULATOR_EVENT_OVER_CURRENT;
688 case REGULATOR_ERROR_REGULATION_OUT:
689 return REGULATOR_EVENT_REGULATION_OUT;
690 case REGULATOR_ERROR_FAIL:
691 return REGULATOR_EVENT_FAIL;
692 case REGULATOR_ERROR_OVER_TEMP:
693 return REGULATOR_EVENT_OVER_TEMP;
694 case REGULATOR_ERROR_UNDER_VOLTAGE_WARN:
695 return REGULATOR_EVENT_UNDER_VOLTAGE_WARN;
696 case REGULATOR_ERROR_OVER_CURRENT_WARN:
697 return REGULATOR_EVENT_OVER_CURRENT_WARN;
698 case REGULATOR_ERROR_OVER_VOLTAGE_WARN:
699 return REGULATOR_EVENT_OVER_VOLTAGE_WARN;
700 case REGULATOR_ERROR_OVER_TEMP_WARN:
701 return REGULATOR_EVENT_OVER_TEMP_WARN;
702 }
703 return 0;
704}
705
706
707struct regulator_dev *
708regulator_register(struct device *dev,
709 const struct regulator_desc *regulator_desc,
710 const struct regulator_config *config);
711struct regulator_dev *
712devm_regulator_register(struct device *dev,
713 const struct regulator_desc *regulator_desc,
714 const struct regulator_config *config);
715void regulator_unregister(struct regulator_dev *rdev);
716
717int regulator_notifier_call_chain(struct regulator_dev *rdev,
718 unsigned long event, void *data);
719void *devm_regulator_irq_helper(struct device *dev,
720 const struct regulator_irq_desc *d, int irq,
721 int irq_flags, int common_errs,
722 int *per_rdev_errs, struct regulator_dev **rdev,
723 int rdev_amount);
724void *regulator_irq_helper(struct device *dev,
725 const struct regulator_irq_desc *d, int irq,
726 int irq_flags, int common_errs, int *per_rdev_errs,
727 struct regulator_dev **rdev, int rdev_amount);
728void regulator_irq_helper_cancel(void **handle);
729int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
730 unsigned long *dev_mask);
731
732void *rdev_get_drvdata(struct regulator_dev *rdev);
733struct device *rdev_get_dev(struct regulator_dev *rdev);
734struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
735int rdev_get_id(struct regulator_dev *rdev);
736
737int regulator_mode_to_status(unsigned int);
738
739int regulator_list_voltage_linear(struct regulator_dev *rdev,
740 unsigned int selector);
741int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
742 unsigned int selector);
743int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
744 unsigned int selector);
745int regulator_list_voltage_table(struct regulator_dev *rdev,
746 unsigned int selector);
747int regulator_map_voltage_linear(struct regulator_dev *rdev,
748 int min_uV, int max_uV);
749int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
750 int min_uV, int max_uV);
751int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
752 int min_uV, int max_uV);
753int regulator_map_voltage_iterate(struct regulator_dev *rdev,
754 int min_uV, int max_uV);
755int regulator_map_voltage_ascend(struct regulator_dev *rdev,
756 int min_uV, int max_uV);
757int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
758int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
759 unsigned int sel);
760int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
761int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
762int regulator_is_enabled_regmap(struct regulator_dev *rdev);
763int regulator_enable_regmap(struct regulator_dev *rdev);
764int regulator_disable_regmap(struct regulator_dev *rdev);
765int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
766 unsigned int old_selector,
767 unsigned int new_selector);
768int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
769int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
770int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
771int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
772
773int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
774 bool enable);
775int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
776 int min_uA, int max_uA);
777int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
778void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
779int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
780 unsigned int num_sel, unsigned int *sel);
781int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay);
782int regulator_sync_voltage_rdev(struct regulator_dev *rdev);
783
784/*
785 * Helper functions intended to be used by regulator drivers prior registering
786 * their regulators.
787 */
788int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
789 unsigned int selector);
790
791int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
792 unsigned int selector);
793
794#ifdef CONFIG_REGULATOR
795const char *rdev_get_name(struct regulator_dev *rdev);
796#else
797static inline const char *rdev_get_name(struct regulator_dev *rdev)
798{
799 return NULL;
800}
801#endif
802
803#endif