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