| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * driver.h -- SoC Regulator driver support. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
|---|
| 7 | 8 | * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | | - * |
|---|
| 12 | 9 | * Regulator Driver Interface. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #ifndef __LINUX_REGULATOR_DRIVER_H_ |
|---|
| 16 | 13 | #define __LINUX_REGULATOR_DRIVER_H_ |
|---|
| 17 | 14 | |
|---|
| 18 | | -#define MAX_COUPLED 4 |
|---|
| 19 | | - |
|---|
| 20 | 15 | #include <linux/device.h> |
|---|
| 16 | +#include <linux/linear_range.h> |
|---|
| 21 | 17 | #include <linux/notifier.h> |
|---|
| 22 | 18 | #include <linux/regulator/consumer.h> |
|---|
| 23 | | -#include <linux/regulator/proxy-consumer.h> |
|---|
| 19 | +#include <linux/ww_mutex.h> |
|---|
| 20 | +#include <linux/android_kabi.h> |
|---|
| 24 | 21 | |
|---|
| 25 | 22 | struct gpio_desc; |
|---|
| 26 | 23 | struct regmap; |
|---|
| .. | .. |
|---|
| 44 | 41 | REGULATOR_STATUS_UNDEFINED, |
|---|
| 45 | 42 | }; |
|---|
| 46 | 43 | |
|---|
| 47 | | -/** |
|---|
| 48 | | - * struct regulator_linear_range - specify linear voltage ranges |
|---|
| 49 | | - * |
|---|
| 50 | | - * Specify a range of voltages for regulator_map_linear_range() and |
|---|
| 51 | | - * regulator_list_linear_range(). |
|---|
| 52 | | - * |
|---|
| 53 | | - * @min_uV: Lowest voltage in range |
|---|
| 54 | | - * @min_sel: Lowest selector for range |
|---|
| 55 | | - * @max_sel: Highest selector for range |
|---|
| 56 | | - * @uV_step: Step size |
|---|
| 57 | | - */ |
|---|
| 58 | | -struct regulator_linear_range { |
|---|
| 59 | | - unsigned int min_uV; |
|---|
| 60 | | - unsigned int min_sel; |
|---|
| 61 | | - unsigned int max_sel; |
|---|
| 62 | | - unsigned int uV_step; |
|---|
| 63 | | -}; |
|---|
| 64 | | - |
|---|
| 65 | | -/* Initialize struct regulator_linear_range */ |
|---|
| 44 | +/* Initialize struct linear_range for regulators */ |
|---|
| 66 | 45 | #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ |
|---|
| 67 | 46 | { \ |
|---|
| 68 | | - .min_uV = _min_uV, \ |
|---|
| 47 | + .min = _min_uV, \ |
|---|
| 69 | 48 | .min_sel = _min_sel, \ |
|---|
| 70 | 49 | .max_sel = _max_sel, \ |
|---|
| 71 | | - .uV_step = _step_uV, \ |
|---|
| 50 | + .step = _step_uV, \ |
|---|
| 72 | 51 | } |
|---|
| 73 | 52 | |
|---|
| 74 | 53 | /** |
|---|
| .. | .. |
|---|
| 139 | 118 | * suspended. |
|---|
| 140 | 119 | * @set_suspend_mode: Set the operating mode for the regulator when the |
|---|
| 141 | 120 | * system is suspended. |
|---|
| 142 | | - * |
|---|
| 121 | + * @resume: Resume operation of suspended regulator. |
|---|
| 143 | 122 | * @set_pull_down: Configure the regulator to pull down when the regulator |
|---|
| 144 | 123 | * is disabled. |
|---|
| 145 | 124 | * |
|---|
| .. | .. |
|---|
| 224 | 203 | int (*resume)(struct regulator_dev *rdev); |
|---|
| 225 | 204 | |
|---|
| 226 | 205 | int (*set_pull_down) (struct regulator_dev *); |
|---|
| 206 | + |
|---|
| 207 | + ANDROID_KABI_RESERVE(1); |
|---|
| 227 | 208 | }; |
|---|
| 228 | 209 | |
|---|
| 229 | 210 | /* |
|---|
| .. | .. |
|---|
| 245 | 226 | * @name: Identifying name for the regulator. |
|---|
| 246 | 227 | * @supply_name: Identifying the regulator supply |
|---|
| 247 | 228 | * @of_match: Name used to identify regulator in DT. |
|---|
| 229 | + * @of_match_full_name: A flag to indicate that the of_match string, if |
|---|
| 230 | + * present, should be matched against the node full_name. |
|---|
| 248 | 231 | * @regulators_node: Name of node containing regulator definitions in DT. |
|---|
| 249 | 232 | * @of_parse_cb: Optional callback called only if of_match is present. |
|---|
| 250 | 233 | * Will be called for each regulator parsed from DT, during |
|---|
| .. | .. |
|---|
| 264 | 247 | * @continuous_voltage_range: Indicates if the regulator can set any |
|---|
| 265 | 248 | * voltage within constrains range. |
|---|
| 266 | 249 | * @n_voltages: Number of selectors available for ops.list_voltage(). |
|---|
| 250 | + * @n_current_limits: Number of selectors available for current limits |
|---|
| 267 | 251 | * |
|---|
| 268 | 252 | * @min_uV: Voltage given by the lowest selector (if linear mapping) |
|---|
| 269 | 253 | * @uV_step: Voltage increase with each selector (if linear mapping) |
|---|
| .. | .. |
|---|
| 272 | 256 | * @ramp_delay: Time to settle down after voltage change (unit: uV/us) |
|---|
| 273 | 257 | * @min_dropout_uV: The minimum dropout voltage this regulator can handle |
|---|
| 274 | 258 | * @linear_ranges: A constant table of possible voltage ranges. |
|---|
| 275 | | - * @n_linear_ranges: Number of entries in the @linear_ranges table. |
|---|
| 259 | + * @linear_range_selectors: A constant table of voltage range selectors. |
|---|
| 260 | + * If pickable ranges are used each range must |
|---|
| 261 | + * have corresponding selector here. |
|---|
| 262 | + * @n_linear_ranges: Number of entries in the @linear_ranges (and in |
|---|
| 263 | + * linear_range_selectors if used) table(s). |
|---|
| 276 | 264 | * @volt_table: Voltage mapping table (if table based mapping) |
|---|
| 265 | + * @curr_table: Current limit mapping table (if table based mapping) |
|---|
| 277 | 266 | * |
|---|
| 278 | | - * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ |
|---|
| 267 | + * @vsel_range_reg: Register for range selector when using pickable ranges |
|---|
| 268 | + * and ``regulator_map_*_voltage_*_pickable`` functions. |
|---|
| 269 | + * @vsel_range_mask: Mask for register bitfield used for range selector |
|---|
| 270 | + * @vsel_reg: Register for selector when using ``regulator_map_*_voltage_*`` |
|---|
| 279 | 271 | * @vsel_mask: Mask for register bitfield used for selector |
|---|
| 280 | | - * @csel_reg: Register for TPS65218 LS3 current regulator |
|---|
| 281 | | - * @csel_mask: Mask for TPS65218 LS3 current regulator |
|---|
| 272 | + * @vsel_step: Specify the resolution of selector stepping when setting |
|---|
| 273 | + * voltage. If 0, then no stepping is done (requested selector is |
|---|
| 274 | + * set directly), if >0 then the regulator API will ramp the |
|---|
| 275 | + * voltage up/down gradually each time increasing/decreasing the |
|---|
| 276 | + * selector by the specified step value. |
|---|
| 277 | + * @csel_reg: Register for current limit selector using regmap set_current_limit |
|---|
| 278 | + * @csel_mask: Mask for register bitfield used for current limit selector |
|---|
| 282 | 279 | * @apply_reg: Register for initiate voltage change on the output when |
|---|
| 283 | 280 | * using regulator_set_voltage_sel_regmap |
|---|
| 284 | 281 | * @apply_bit: Register bitfield used for initiate voltage change on the |
|---|
| .. | .. |
|---|
| 313 | 310 | * @enable_time: Time taken for initial enable of regulator (in uS). |
|---|
| 314 | 311 | * @off_on_delay: guard time (in uS), before re-enabling a regulator |
|---|
| 315 | 312 | * |
|---|
| 313 | + * @poll_enabled_time: The polling interval (in uS) to use while checking that |
|---|
| 314 | + * the regulator was actually enabled. Max upto enable_time. |
|---|
| 315 | + * |
|---|
| 316 | 316 | * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode |
|---|
| 317 | 317 | */ |
|---|
| 318 | 318 | struct regulator_desc { |
|---|
| 319 | 319 | const char *name; |
|---|
| 320 | 320 | const char *supply_name; |
|---|
| 321 | 321 | const char *of_match; |
|---|
| 322 | + bool of_match_full_name; |
|---|
| 322 | 323 | const char *regulators_node; |
|---|
| 323 | 324 | int (*of_parse_cb)(struct device_node *, |
|---|
| 324 | 325 | const struct regulator_desc *, |
|---|
| .. | .. |
|---|
| 326 | 327 | int id; |
|---|
| 327 | 328 | unsigned int continuous_voltage_range:1; |
|---|
| 328 | 329 | unsigned n_voltages; |
|---|
| 330 | + unsigned int n_current_limits; |
|---|
| 329 | 331 | const struct regulator_ops *ops; |
|---|
| 330 | 332 | int irq; |
|---|
| 331 | 333 | enum regulator_type type; |
|---|
| .. | .. |
|---|
| 338 | 340 | unsigned int ramp_delay; |
|---|
| 339 | 341 | int min_dropout_uV; |
|---|
| 340 | 342 | |
|---|
| 341 | | - const struct regulator_linear_range *linear_ranges; |
|---|
| 343 | + const struct linear_range *linear_ranges; |
|---|
| 344 | + const unsigned int *linear_range_selectors; |
|---|
| 345 | + |
|---|
| 342 | 346 | int n_linear_ranges; |
|---|
| 343 | 347 | |
|---|
| 344 | 348 | const unsigned int *volt_table; |
|---|
| 349 | + const unsigned int *curr_table; |
|---|
| 345 | 350 | |
|---|
| 351 | + unsigned int vsel_range_reg; |
|---|
| 352 | + unsigned int vsel_range_mask; |
|---|
| 346 | 353 | unsigned int vsel_reg; |
|---|
| 347 | 354 | unsigned int vsel_mask; |
|---|
| 355 | + unsigned int vsel_step; |
|---|
| 348 | 356 | unsigned int csel_reg; |
|---|
| 349 | 357 | unsigned int csel_mask; |
|---|
| 350 | 358 | unsigned int apply_reg; |
|---|
| .. | .. |
|---|
| 373 | 381 | |
|---|
| 374 | 382 | unsigned int off_on_delay; |
|---|
| 375 | 383 | |
|---|
| 384 | + unsigned int poll_enabled_time; |
|---|
| 385 | + |
|---|
| 376 | 386 | unsigned int (*of_map_mode)(unsigned int mode); |
|---|
| 387 | + |
|---|
| 388 | + ANDROID_KABI_RESERVE(1); |
|---|
| 377 | 389 | }; |
|---|
| 378 | 390 | |
|---|
| 379 | 391 | /** |
|---|
| .. | .. |
|---|
| 390 | 402 | * NULL). |
|---|
| 391 | 403 | * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is |
|---|
| 392 | 404 | * insufficient. |
|---|
| 393 | | - * @ena_gpio_initialized: GPIO controlling regulator enable was properly |
|---|
| 394 | | - * initialized, meaning that >= 0 is a valid gpio |
|---|
| 395 | | - * identifier and < 0 is a non existent gpio. |
|---|
| 396 | | - * @ena_gpio: GPIO controlling regulator enable. |
|---|
| 397 | | - * @ena_gpiod: GPIO descriptor controlling regulator enable. |
|---|
| 398 | | - * @ena_gpio_invert: Sense for GPIO enable control. |
|---|
| 399 | | - * @ena_gpio_flags: Flags to use when calling gpio_request_one() |
|---|
| 405 | + * @ena_gpiod: GPIO controlling regulator enable. |
|---|
| 400 | 406 | */ |
|---|
| 401 | 407 | struct regulator_config { |
|---|
| 402 | 408 | struct device *dev; |
|---|
| .. | .. |
|---|
| 405 | 411 | struct device_node *of_node; |
|---|
| 406 | 412 | struct regmap *regmap; |
|---|
| 407 | 413 | |
|---|
| 408 | | - bool ena_gpio_initialized; |
|---|
| 409 | | - int ena_gpio; |
|---|
| 410 | 414 | struct gpio_desc *ena_gpiod; |
|---|
| 411 | | - unsigned int ena_gpio_invert:1; |
|---|
| 412 | | - unsigned int ena_gpio_flags; |
|---|
| 413 | 415 | }; |
|---|
| 414 | 416 | |
|---|
| 415 | 417 | /* |
|---|
| .. | .. |
|---|
| 421 | 423 | * incremented. |
|---|
| 422 | 424 | */ |
|---|
| 423 | 425 | struct coupling_desc { |
|---|
| 424 | | - struct regulator_dev *coupled_rdevs[MAX_COUPLED]; |
|---|
| 426 | + struct regulator_dev **coupled_rdevs; |
|---|
| 427 | + struct regulator_coupler *coupler; |
|---|
| 425 | 428 | int n_resolved; |
|---|
| 426 | 429 | int n_coupled; |
|---|
| 427 | 430 | }; |
|---|
| .. | .. |
|---|
| 452 | 455 | struct coupling_desc coupling_desc; |
|---|
| 453 | 456 | |
|---|
| 454 | 457 | struct blocking_notifier_head notifier; |
|---|
| 455 | | - struct mutex mutex; /* consumer lock */ |
|---|
| 458 | + struct ww_mutex mutex; /* consumer lock */ |
|---|
| 456 | 459 | struct task_struct *mutex_owner; |
|---|
| 457 | 460 | int ref_cnt; |
|---|
| 458 | 461 | struct module *owner; |
|---|
| .. | .. |
|---|
| 463 | 466 | struct regmap *regmap; |
|---|
| 464 | 467 | |
|---|
| 465 | 468 | struct delayed_work disable_work; |
|---|
| 466 | | - int deferred_disables; |
|---|
| 467 | 469 | |
|---|
| 468 | 470 | void *reg_data; /* regulator_dev data */ |
|---|
| 469 | 471 | |
|---|
| .. | .. |
|---|
| 476 | 478 | |
|---|
| 477 | 479 | /* time when this regulator was disabled last time */ |
|---|
| 478 | 480 | unsigned long last_off_jiffy; |
|---|
| 479 | | - struct proxy_consumer *proxy_consumer; |
|---|
| 481 | + |
|---|
| 482 | + ANDROID_KABI_RESERVE(1); |
|---|
| 480 | 483 | }; |
|---|
| 481 | 484 | |
|---|
| 482 | 485 | struct regulator_dev * |
|---|
| .. | .. |
|---|
| 487 | 490 | const struct regulator_desc *regulator_desc, |
|---|
| 488 | 491 | const struct regulator_config *config); |
|---|
| 489 | 492 | void regulator_unregister(struct regulator_dev *rdev); |
|---|
| 490 | | -void regulator_sync_state(struct device *dev); |
|---|
| 491 | 493 | void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev); |
|---|
| 492 | 494 | |
|---|
| 493 | 495 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
|---|
| .. | .. |
|---|
| 495 | 497 | |
|---|
| 496 | 498 | void *rdev_get_drvdata(struct regulator_dev *rdev); |
|---|
| 497 | 499 | struct device *rdev_get_dev(struct regulator_dev *rdev); |
|---|
| 500 | +struct regmap *rdev_get_regmap(struct regulator_dev *rdev); |
|---|
| 498 | 501 | int rdev_get_id(struct regulator_dev *rdev); |
|---|
| 499 | 502 | |
|---|
| 500 | 503 | int regulator_mode_to_status(unsigned int); |
|---|
| 501 | 504 | |
|---|
| 502 | 505 | int regulator_list_voltage_linear(struct regulator_dev *rdev, |
|---|
| 503 | 506 | unsigned int selector); |
|---|
| 507 | +int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, |
|---|
| 508 | + unsigned int selector); |
|---|
| 504 | 509 | int regulator_list_voltage_linear_range(struct regulator_dev *rdev, |
|---|
| 505 | 510 | unsigned int selector); |
|---|
| 506 | 511 | int regulator_list_voltage_table(struct regulator_dev *rdev, |
|---|
| 507 | 512 | unsigned int selector); |
|---|
| 508 | 513 | int regulator_map_voltage_linear(struct regulator_dev *rdev, |
|---|
| 509 | 514 | int min_uV, int max_uV); |
|---|
| 515 | +int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, |
|---|
| 516 | + int min_uV, int max_uV); |
|---|
| 510 | 517 | int regulator_map_voltage_linear_range(struct regulator_dev *rdev, |
|---|
| 511 | 518 | int min_uV, int max_uV); |
|---|
| 512 | 519 | int regulator_map_voltage_iterate(struct regulator_dev *rdev, |
|---|
| 513 | 520 | int min_uV, int max_uV); |
|---|
| 514 | 521 | int regulator_map_voltage_ascend(struct regulator_dev *rdev, |
|---|
| 515 | 522 | int min_uV, int max_uV); |
|---|
| 523 | +int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); |
|---|
| 524 | +int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, |
|---|
| 525 | + unsigned int sel); |
|---|
| 516 | 526 | int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); |
|---|
| 517 | 527 | int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); |
|---|
| 518 | 528 | int regulator_is_enabled_regmap(struct regulator_dev *rdev); |
|---|
| .. | .. |
|---|
| 528 | 538 | |
|---|
| 529 | 539 | int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, |
|---|
| 530 | 540 | bool enable); |
|---|
| 541 | +int regulator_set_current_limit_regmap(struct regulator_dev *rdev, |
|---|
| 542 | + int min_uA, int max_uA); |
|---|
| 543 | +int regulator_get_current_limit_regmap(struct regulator_dev *rdev); |
|---|
| 531 | 544 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); |
|---|
| 532 | 545 | |
|---|
| 546 | +/* |
|---|
| 547 | + * Helper functions intended to be used by regulator drivers prior registering |
|---|
| 548 | + * their regulators. |
|---|
| 549 | + */ |
|---|
| 550 | +int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, |
|---|
| 551 | + unsigned int selector); |
|---|
| 552 | + |
|---|
| 533 | 553 | #endif |
|---|