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 * @enable_time: Time taken for initial enable of regulator (in uS). 341 * @off_on_delay: guard time (in uS), before re-enabling a regulator 342 * 343 * @poll_enabled_time: The polling interval (in uS) to use while checking that 344 * the regulator was actually enabled. Max upto enable_time. 345 * 346 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode 347 */ 348 struct regulator_desc { 349 const char *name; 350 const char *supply_name; 351 const char *of_match; 352 bool of_match_full_name; 353 const char *regulators_node; 354 int (*of_parse_cb)(struct device_node *, 355 const struct regulator_desc *, 356 struct regulator_config *); 357 int id; 358 unsigned int continuous_voltage_range:1; 359 unsigned n_voltages; 360 unsigned int n_current_limits; 361 const struct regulator_ops *ops; 362 int irq; 363 enum regulator_type type; 364 struct module *owner; 365 366 unsigned int min_uV; 367 unsigned int uV_step; 368 unsigned int linear_min_sel; 369 int fixed_uV; 370 unsigned int ramp_delay; 371 int min_dropout_uV; 372 373 const struct linear_range *linear_ranges; 374 const unsigned int *linear_range_selectors; 375 376 int n_linear_ranges; 377 378 const unsigned int *volt_table; 379 const unsigned int *curr_table; 380 381 unsigned int vsel_range_reg; 382 unsigned int vsel_range_mask; 383 unsigned int vsel_reg; 384 unsigned int vsel_mask; 385 unsigned int vsel_step; 386 unsigned int csel_reg; 387 unsigned int csel_mask; 388 unsigned int apply_reg; 389 unsigned int apply_bit; 390 unsigned int enable_reg; 391 unsigned int enable_mask; 392 unsigned int enable_val; 393 unsigned int disable_val; 394 bool enable_is_inverted; 395 unsigned int bypass_reg; 396 unsigned int bypass_mask; 397 unsigned int bypass_val_on; 398 unsigned int bypass_val_off; 399 unsigned int active_discharge_on; 400 unsigned int active_discharge_off; 401 unsigned int active_discharge_mask; 402 unsigned int active_discharge_reg; 403 unsigned int soft_start_reg; 404 unsigned int soft_start_mask; 405 unsigned int soft_start_val_on; 406 unsigned int pull_down_reg; 407 unsigned int pull_down_mask; 408 unsigned int pull_down_val_on; 409 unsigned int ramp_reg; 410 unsigned int ramp_mask; 411 const unsigned int *ramp_delay_table; 412 unsigned int n_ramp_values; 413 414 unsigned int enable_time; 415 416 unsigned int off_on_delay; 417 418 unsigned int poll_enabled_time; 419 420 unsigned int (*of_map_mode)(unsigned int mode); 421 }; 422 423 /** 424 * struct regulator_config - Dynamic regulator descriptor 425 * 426 * Each regulator registered with the core is described with a 427 * structure of this type and a struct regulator_desc. This structure 428 * contains the runtime variable parts of the regulator description. 429 * 430 * @dev: struct device for the regulator 431 * @init_data: platform provided init data, passed through by driver 432 * @driver_data: private regulator data 433 * @of_node: OpenFirmware node to parse for device tree bindings (may be 434 * NULL). 435 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is 436 * insufficient. 437 * @ena_gpiod: GPIO controlling regulator enable. 438 */ 439 struct regulator_config { 440 struct device *dev; 441 const struct regulator_init_data *init_data; 442 void *driver_data; 443 struct device_node *of_node; 444 struct regmap *regmap; 445 446 struct gpio_desc *ena_gpiod; 447 }; 448 449 /** 450 * struct regulator_err_state - regulator error/notification status 451 * 452 * @rdev: Regulator which status the struct indicates. 453 * @notifs: Events which have occurred on the regulator. 454 * @errors: Errors which are active on the regulator. 455 * @possible_errs: Errors which can be signaled (by given IRQ). 456 */ 457 struct regulator_err_state { 458 struct regulator_dev *rdev; 459 unsigned long notifs; 460 unsigned long errors; 461 int possible_errs; 462 }; 463 464 /** 465 * struct regulator_irq_data - regulator error/notification status date 466 * 467 * @states: Status structs for each of the associated regulators. 468 * @num_states: Amount of associated regulators. 469 * @data: Driver data pointer given at regulator_irq_desc. 470 * @opaque: Value storage for IC driver. Core does not update this. ICs 471 * may want to store status register value here at map_event and 472 * compare contents at 'renable' callback to see if new problems 473 * have been added to status. If that is the case it may be 474 * desirable to return REGULATOR_ERROR_CLEARED and not 475 * REGULATOR_ERROR_ON to allow IRQ fire again and to generate 476 * notifications also for the new issues. 477 * 478 * This structure is passed to 'map_event' and 'renable' callbacks for 479 * reporting regulator status to core. 480 */ 481 struct regulator_irq_data { 482 struct regulator_err_state *states; 483 int num_states; 484 void *data; 485 long opaque; 486 }; 487 488 /** 489 * struct regulator_irq_desc - notification sender for IRQ based events. 490 * 491 * @name: The visible name for the IRQ 492 * @fatal_cnt: If this IRQ is used to signal HW damaging condition it may be 493 * best to shut-down regulator(s) or reboot the SOC if error 494 * handling is repeatedly failing. If fatal_cnt is given the IRQ 495 * handling is aborted if it fails for fatal_cnt times and die() 496 * callback (if populated) or BUG() is called to try to prevent 497 * further damage. 498 * @reread_ms: The time which is waited before attempting to re-read status 499 * at the worker if IC reading fails. Immediate re-read is done 500 * if time is not specified. 501 * @irq_off_ms: The time which IRQ is kept disabled before re-evaluating the 502 * status for devices which keep IRQ disabled for duration of the 503 * error. If this is not given the IRQ is left enabled and renable 504 * is not called. 505 * @skip_off: If set to true the IRQ handler will attempt to check if any of 506 * the associated regulators are enabled prior to taking other 507 * actions. If no regulators are enabled and this is set to true 508 * a spurious IRQ is assumed and IRQ_NONE is returned. 509 * @high_prio: Boolean to indicate that high priority WQ should be used. 510 * @data: Driver private data pointer which will be passed as such to 511 * the renable, map_event and die callbacks in regulator_irq_data. 512 * @die: Protection callback. If IC status reading or recovery actions 513 * fail fatal_cnt times this callback or BUG() is called. This 514 * callback should implement a final protection attempt like 515 * disabling the regulator. If protection succeeded this may 516 * return 0. If anything else is returned the core assumes final 517 * protection failed and calls BUG() as a last resort. 518 * @map_event: Driver callback to map IRQ status into regulator devices with 519 * events / errors. NOTE: callback MUST initialize both the 520 * errors and notifs for all rdevs which it signals having 521 * active events as core does not clean the map data. 522 * REGULATOR_FAILED_RETRY can be returned to indicate that the 523 * status reading from IC failed. If this is repeated for 524 * fatal_cnt times the core will call die() callback or BUG() 525 * as a last resort to protect the HW. 526 * @renable: Optional callback to check status (if HW supports that) before 527 * re-enabling IRQ. If implemented this should clear the error 528 * flags so that errors fetched by regulator_get_error_flags() 529 * are updated. If callback is not implemented then errors are 530 * assumed to be cleared and IRQ is re-enabled. 531 * REGULATOR_FAILED_RETRY can be returned to 532 * indicate that the status reading from IC failed. If this is 533 * repeated for 'fatal_cnt' times the core will call die() 534 * callback or BUG() as a last resort to protect the HW. 535 * Returning zero indicates that the problem in HW has been solved 536 * and IRQ will be re-enabled. Returning REGULATOR_ERROR_ON 537 * indicates the error condition is still active and keeps IRQ 538 * disabled. Please note that returning REGULATOR_ERROR_ON does 539 * not retrigger evaluating what events are active or resending 540 * notifications. If this is needed you probably want to return 541 * zero and allow IRQ to retrigger causing events to be 542 * re-evaluated and re-sent. 543 * 544 * This structure is used for registering regulator IRQ notification helper. 545 */ 546 struct regulator_irq_desc { 547 const char *name; 548 int irq_flags; 549 int fatal_cnt; 550 int reread_ms; 551 int irq_off_ms; 552 bool skip_off; 553 bool high_prio; 554 void *data; 555 556 int (*die)(struct regulator_irq_data *rid); 557 int (*map_event)(int irq, struct regulator_irq_data *rid, 558 unsigned long *dev_mask); 559 int (*renable)(struct regulator_irq_data *rid); 560 }; 561 562 /* 563 * Return values for regulator IRQ helpers. 564 */ 565 enum { 566 REGULATOR_ERROR_CLEARED, 567 REGULATOR_FAILED_RETRY, 568 REGULATOR_ERROR_ON, 569 }; 570 571 /* 572 * struct coupling_desc 573 * 574 * Describes coupling of regulators. Each regulator should have 575 * at least a pointer to itself in coupled_rdevs array. 576 * When a new coupled regulator is resolved, n_resolved is 577 * incremented. 578 */ 579 struct coupling_desc { 580 struct regulator_dev **coupled_rdevs; 581 struct regulator_coupler *coupler; 582 int n_resolved; 583 int n_coupled; 584 }; 585 586 /* 587 * struct regulator_dev 588 * 589 * Voltage / Current regulator class device. One for each 590 * regulator. 591 * 592 * This should *not* be used directly by anything except the regulator 593 * core and notification injection (which should take the mutex and do 594 * no other direct access). 595 */ 596 struct regulator_dev { 597 const struct regulator_desc *desc; 598 int exclusive; 599 u32 use_count; 600 u32 open_count; 601 u32 bypass_count; 602 603 /* lists we belong to */ 604 struct list_head list; /* list of all regulators */ 605 606 /* lists we own */ 607 struct list_head consumer_list; /* consumers we supply */ 608 609 struct coupling_desc coupling_desc; 610 611 struct blocking_notifier_head notifier; 612 struct ww_mutex mutex; /* consumer lock */ 613 struct task_struct *mutex_owner; 614 int ref_cnt; 615 struct module *owner; 616 struct device dev; 617 struct regulation_constraints *constraints; 618 struct regulator *supply; /* for tree */ 619 const char *supply_name; 620 struct regmap *regmap; 621 622 struct delayed_work disable_work; 623 624 void *reg_data; /* regulator_dev data */ 625 626 struct dentry *debugfs; 627 628 struct regulator_enable_gpio *ena_pin; 629 unsigned int ena_gpio_state:1; 630 631 unsigned int is_switch:1; 632 633 /* time when this regulator was disabled last time */ 634 ktime_t last_off; 635 int cached_err; 636 bool use_cached_err; 637 spinlock_t err_lock; 638 }; 639 640 struct regulator_dev * 641 regulator_register(const struct regulator_desc *regulator_desc, 642 const struct regulator_config *config); 643 struct regulator_dev * 644 devm_regulator_register(struct device *dev, 645 const struct regulator_desc *regulator_desc, 646 const struct regulator_config *config); 647 void regulator_unregister(struct regulator_dev *rdev); 648 void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev); 649 650 int regulator_notifier_call_chain(struct regulator_dev *rdev, 651 unsigned long event, void *data); 652 void *devm_regulator_irq_helper(struct device *dev, 653 const struct regulator_irq_desc *d, int irq, 654 int irq_flags, int common_errs, 655 int *per_rdev_errs, struct regulator_dev **rdev, 656 int rdev_amount); 657 void *regulator_irq_helper(struct device *dev, 658 const struct regulator_irq_desc *d, int irq, 659 int irq_flags, int common_errs, int *per_rdev_errs, 660 struct regulator_dev **rdev, int rdev_amount); 661 void regulator_irq_helper_cancel(void **handle); 662 663 void *rdev_get_drvdata(struct regulator_dev *rdev); 664 struct device *rdev_get_dev(struct regulator_dev *rdev); 665 struct regmap *rdev_get_regmap(struct regulator_dev *rdev); 666 int rdev_get_id(struct regulator_dev *rdev); 667 668 int regulator_mode_to_status(unsigned int); 669 670 int regulator_list_voltage_linear(struct regulator_dev *rdev, 671 unsigned int selector); 672 int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, 673 unsigned int selector); 674 int regulator_list_voltage_linear_range(struct regulator_dev *rdev, 675 unsigned int selector); 676 int regulator_list_voltage_table(struct regulator_dev *rdev, 677 unsigned int selector); 678 int regulator_map_voltage_linear(struct regulator_dev *rdev, 679 int min_uV, int max_uV); 680 int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, 681 int min_uV, int max_uV); 682 int regulator_map_voltage_linear_range(struct regulator_dev *rdev, 683 int min_uV, int max_uV); 684 int regulator_map_voltage_iterate(struct regulator_dev *rdev, 685 int min_uV, int max_uV); 686 int regulator_map_voltage_ascend(struct regulator_dev *rdev, 687 int min_uV, int max_uV); 688 int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); 689 int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, 690 unsigned int sel); 691 int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); 692 int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); 693 int regulator_is_enabled_regmap(struct regulator_dev *rdev); 694 int regulator_enable_regmap(struct regulator_dev *rdev); 695 int regulator_disable_regmap(struct regulator_dev *rdev); 696 int regulator_set_voltage_time_sel(struct regulator_dev *rdev, 697 unsigned int old_selector, 698 unsigned int new_selector); 699 int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); 700 int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); 701 int regulator_set_soft_start_regmap(struct regulator_dev *rdev); 702 int regulator_set_pull_down_regmap(struct regulator_dev *rdev); 703 704 int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, 705 bool enable); 706 int regulator_set_current_limit_regmap(struct regulator_dev *rdev, 707 int min_uA, int max_uA); 708 int regulator_get_current_limit_regmap(struct regulator_dev *rdev); 709 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 710 int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay); 711 int regulator_sync_voltage_rdev(struct regulator_dev *rdev); 712 713 /* 714 * Helper functions intended to be used by regulator drivers prior registering 715 * their regulators. 716 */ 717 int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, 718 unsigned int selector); 719 720 int regulator_desc_list_voltage_linear(const struct regulator_desc *desc, 721 unsigned int selector); 722 723 #ifdef CONFIG_REGULATOR 724 const char *rdev_get_name(struct regulator_dev *rdev); 725 #else 726 static inline const char *rdev_get_name(struct regulator_dev *rdev) 727 { 728 return NULL; 729 } 730 #endif 731 732 #endif 733